我有这个Mongo DB
查询,它以我期望的格式返回:
db.getCollection("myCollection").aggregate([
{
$lookup: {
from: "myCollection",
localField: "parent_id",
foreignField: "parent_id",
as: "children"
}
},
{ $unwind: "$children" },
{ $replaceWith: "$children" }
])
然而,我还希望在我的响应中在子文档中返回为only present in the parent docs的parent_desc
字段
example child doc:
{
id: doc_123_2
parent_id: 123
active: true
}
example parent doc:
{
_id: doc_123
parent_id: 123
active: true
parent_desc: sample parent desc
}
如何修改我的查询来做到这一点?