Node.js 嵌套引用以填充mongoose 5.0节点
我有两个模型。第一个是UserSchema,第二个是CategorySchemaNode.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
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内填充出版物类别此链接位于链接和说明中。太清楚了