Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 嵌套引用以填充mongoose 5.0节点_Node.js_Mongoose_Mongoose Schema_Mongoose Populate_Mongoose Plugins - Fatal编程技术网

Node.js 嵌套引用以填充mongoose 5.0节点

Node.js 嵌套引用以填充mongoose 5.0节点,node.js,mongoose,mongoose-schema,mongoose-populate,mongoose-plugins,Node.js,Mongoose,Mongoose Schema,Mongoose Populate,Mongoose Plugins,我有两个模型。第一个是UserSchema,第二个是CategorySchema var UserSchema = Schema({ firstName: { type: String, required: true }, secondName: String, lastName: { type: String, required: true }, email: { t

我有两个模型。第一个是UserSchema,第二个是CategorySchema

var UserSchema = Schema({
    firstName: {
        type: String,
        required: true
    },
    secondName: String,
    lastName: {
        type: String,
        required: true
    },
    email: {
        type: String,
        unique: true,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    status: {
        type: String,
        required: true
    },
    roles: [{
        type: Schema.ObjectId,
        ref: 'Role'
    }],

    publications: [{
        title: {
            type: String,

        },
        description: String,
        status: {
            type: String,

        },
        createdAt: {
            type: Date
        },
        updatedAt: {
            type: Date,
            default: Date.now()
        },

        pictures: [{
            name: String
        }],

        categories: [{
            type: Schema.Types.ObjectId,
            ref: 'Category'
        }],...
模型类别为

var CategorySchema = Schema({
    name: String,
    subcategories: [{
        name: String
    }]
});
UserSchema具有发布。出版物包含一个数组。在出版物的内部是包含子类别id数组的类别(子类别是CategorySchema的whithin)


问题是何时需要填充UserSchema的类别。UserSchema的类别具有属于CategorySchema的子类别的_id数组

我不明白填充userSchema的类别是什么意思,你是指userSchema中的发布类别吗?是的。在UserSchemain内填充出版物类别此链接位于链接和说明中。太清楚了