基本上我不想将任何键投射到输出中,只是我从查找连接获取的对象...
这是我的代码:
PodMembers.aggregate([
{ $match: { instaid: ObjectId('5a27ed8e1990c12cc0310996'), datetime: { $exists: true } } },
{
$lookup: {
from: "pods",
localField: "pod_id",
foreignField: "_id",
as: "podinfo"
}
},
{ $unwind: "$podinfo" },
{
$group: {
_id:"$podinfo"
}
},
{ $addFields: { Status: true } }
])
我得到了以下输出:
答案 0 :(得分:1)
您可以使用$replaceRoot (aggregation)替换根元素
PodMembers.aggregate([
{ "$match": { "instaid": ObjectId('5a27ed8e1990c12cc0310996'), "datetime": { "$exists": true } } },
{ "$lookup": {
"from": "pods",
"localField": "pod_id",
"foreignField": "_id",
"as": "podinfo"
}},
{ "$unwind": "$podinfo" },
{ "$group": {
"_id":"$podinfo"
}},
{ "$replaceRoot": { "newRoot": "$_id" } },
{ "$addFields": { Status: true } }
])