尝试填充同一集合中的数据。 该文档具有名为上载的键,该键具有对象数组。我需要在同一集合中使用基于 _id 的相同数据。在 university.mediaOptions.schedule.poe._upload 下,我保存了相同的 _id ,该映射到 university.uploads._id 。
我尝试过这样:
{
path: 'university.mediaOptions.schedule.poe._upload',
model: 'campus.uploads._id',
select: 'name url'
}
样本文档:
db.university.findOne();
Output: {
_id: "122321"
uploads: [{
_id: "1",
name: "Sham",
url: "www.sample.com"
}],
university: {
mediaOptions: [{
schedule: [
{
_id: "21"
poe: [{ _upload: "1" }]
}
]
}]
}
}
var populate = [
{
path: 'university.mediaOptions.schedule.poe._upload',
model: 'campus.uploads._id',
select: 'name url'
},
]
出现错误“尚未为模型“ university.uploads._id”注册架构”
Expected Output: {
_id: "122321"
uploads: [{
_id: "1",
name: "Sham",
url: "www.sample.com"
}],
university: {
mediaOptions: [{
schedule: [
{
_id: "21"
poe: [{ _upload: {
_id: "1",
name: "Sham",
url: "www.sample.com"
} }]
}
]
}]
}
}
使用猫鼬