我有这个文件:
[
{
_id: "54d278b2b6d57eee9f2c6d02",
title: "Piping",
mainCategories: [
{
title: "Shut valves",
subCategories: [
{
title: "Ball valve",
userCodeSyntax: "AV2",
typeComponents: [
"54d278b2b6d57eee9f2c6d00",
"54d278b2b6d57eee9f2c6d01"
]
}
]
}
]
}
]
这是一个类别架构,其中typeComponents包含一个包含该类别产品的列表。
我的模特:
var disciplineSchema = new Schema({
title: {type:String, required:true},
project:{
type: Schema.ObjectId,
ref: 'Project'
},
mainCategories:[
{
title: {type:String, required: true},
subCategories:[
{
title: {type:String, required: true},
userCodeSyntax: {type:String, required: true},
externalCode:String,
typeComponents:[ {type: Schema.ObjectId, ref: 'TypeComponent'}]
}
]
}
]
});
是否可以填充typeComponents?
我尝试了这个:
mongoose.model('Discipline').find()
.exec(function(err, disciplines){
var options = {
path: 'mainCategories.subCategories',
model: 'TypeComponent'
};
mongoose.model('Discipline').populate(disciplines, options, function (err, res) {
callback.status(200).send(res)
});
});
您缺少.typeComponents
填充路径的一部分。
当我尝试使用您的文档和typecomponents
集合中具有匹配_id
值的几个文档尝试此方法时,此方法有效:
mongoose.model('Discipline').find()
.exec(function(err, disciplines){
var options = {
path: 'mainCategories.subCategories.typeComponents',
model: 'TypeComponent'
};
mongoose.model('Discipline').populate(disciplines, options, function (err, res) {
callback.status(200).send(res)
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句