var productSchema = new Schema({
name: String,
details : [{ name: String, description: String }]
})
var listSchema = new Schema({
name: String,
products: [{
product_id: { type: Schema.Types.ObjectId, ref: 'Product' },
product_vid: { type: Schema.Types.ObjectId, ref: 'Product.details' }
}]
})
我该怎么办的列表查询,只有一个细节,它匹配product_vid相应的product_id?
List.findById(list_id)
.populate({
path: 'products.product_id',
populate: {
path: 'products.product_vid'
}
})
.exec(function(err, doc){
......
}
它不工作......我以前试过。它显示错误说:“架构尚未注册模型product.details” – tellingeric
您的意思是product.detail或products.product_id?好的..我想这是错误的。 product_vid:{type:Schema.Types.ObjectId,ref:'Product.details'} – enRaiser
但是如何获得正确版本的细节?我只想得到正确的产品和正确的细节..(这就是为什么我把一个product_vid放入列表中的产品数组中) – tellingeric