[英]Mongoose Populate not working in array of sub-document with “path” option
這是我的 Mongoose 架構:
const productSchema = mongoose.Schema({
writer: {
type: Schema.Types.ObjectId,
ref: 'User'
},
schedule: [{
dateTime: {
type: String,
unique: 1
},
candidates: [{
type: Schema.Types.ObjectId,
ref: 'User'
}],
attorn: {
type: Schema.Types.ObjectId,
ref: 'User'
}
}]
...
這是我與候選人一起獲得物品的地方:
Product.find({ '_id': { $in: productIds } })
.populate('writer')
.populate({
path: 'schedule',
populate: {
path: 'candidates',
model: 'User'
}
})
.exec((err, product) => {
if (err) return res.status(400).send(err)
return res.status(200).send(product)
})
你能試試這個嗎
Product.find({ _id: { $in: productIds } })
.populate("writer")
.populate({
path: "schedule.candidates",
})
.populate({
path: "schedule.attorn",
})
.exec((err, product) => {
if (err) return res.status(400).send(err);
return res.status(200).send(product);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.