有没有办法在结果中加入 2 个子文档?
例子:
我有出版商,出版商有出售的包装和书籍。我想要的是只显示他们想要出售的包裹。
这是我的出版商文件:
{
_id: ObjectId('1')
name: "Publisher name 1"
...
packages : [{
_id: ObjectId('p111'),
books: [2222, 3333] //Books IDs
},{
_id: ObjectId('p222'),
books: [4444, 5555] //Books IDs
}],
books: [{
_id: ObjectId('2222'),
name: "Book 2"
},{
_id: ObjectId('3333'),
name: "Book 3"
},
...
]
}
查询:
Publisher.find({_id: 1}, {packages: 1}...);
我想要的是这个结果:
{
_id: ObjectId('1')
name: "Publisher name 1"
...
packages : [{
_id: ObjectId('p111'),
books: [{
_id: ObjectId('2222'),
name: "Book 2"
}, {
_id: ObjectId('3333'),
name: "Book 3"
}] //Books IDs
}
}