Tag: mongoose populate

mongoose,arrays模型上的深度人口

我想深入填充一个可能过于复杂的模型 var ParentSchema = new Schema({ childs: [{type:Schema.ObjectId, ref: 'Child'}], }); var ChildSchema = new Schema({ subject: [{ price: {type: Number}, data: {type: Schema.ObjectId, ref: 'Subject'} }] }) 但是,当我使用正规人群时似乎并不奏效。 我现在安装深度填充,并使用以下内容: Parent.deepPopulate('childs.subjects'); 我想知道是否有一个更简单的方法来完成一个人口众多的主题。

mongoose填充嵌套数组

假设以下3个模型: var CarSchema = new Schema({ name: {type: String}, partIds: [{type: Schema.Types.ObjectId, ref: 'Part'}], }); var PartSchema = new Schema({ name: {type: String}, otherIds: [{type: Schema.Types.ObjectId, ref: 'Other'}], }); var OtherSchema = new Schema({ name: {type: String} }); 当我查询汽车时,我可以填充零件: Car.find().populate('partIds').exec(function(err, cars) { // list of cars with partIds populated }); 有没有mongoose的方式来填充所有汽车的嵌套零件对象otherIds。 Car.find().populate('partIds').exec(function(err, cars) { // […]