Arrays 如何使用mongo函数匹配数组中的objectid?
我们可以在两个数组中匹配objectid,使用mongo聚合组合数据,还是需要使用承诺Arrays 如何使用mongo函数匹配数组中的objectid?,arrays,match,Arrays,Match,我们可以在两个数组中匹配objectid,使用mongo聚合组合数据,还是需要使用承诺 Collection2 { DId: ObjectId("5e3407a40a5c8123cfb0deb7"), DInfo : [{"SectionEdited": true, "SectionID": ObjectId("5e314c5021c3f94eea31c7c2")}, {"SectionComments": "BBBB","SectionEdited": false,"SectionID": O
Collection2
{
DId: ObjectId("5e3407a40a5c8123cfb0deb7"),
DInfo : [{"SectionEdited": true,
"SectionID": ObjectId("5e314c5021c3f94eea31c7c2")},
{"SectionComments": "BBBB","SectionEdited": false,"SectionID": ObjectId("5e314c5021c3f94eea31c7c1")}]
}
Collection 1
{DId: ObjectId("5e3407a40a5c8123cfb0deb7"),DDetails : [{SDetails: {SN: Section1,SSD: [{_id = ObjectId("5e314c5021c3f94eea31c7c1"),SectionQues: "Ques1"
}]}}]}
要求的结果
{DId:ObjectId(“5e3407a40a5c8123cfb0deb7”)
DD:[{SD:{SN:Section1,SSD:[{U id=ObjectId(“5e314c5021c3f94eea31c7c1”),SQ:“Ques1”,“SC:“BBBB”,“SE”:false
}]}}]}如果您正在使用两列ID查找联接,则可以通过
$lookup
{
$lookup:
{
from: <collection to join>,
localField: <field from the input documents()>,
foreignField: <field from the documents of the "from" collection>,
as: <output array field>
}
}
{
$lookup:
{
发件人:,
localField:,
外域:,
作为:
}
}
您可以使用localField
中第一个表的objectid字段和foreignField
中下一个表的objectid字段
您可以查看详细信息如果您可以提供您所拥有和所需的示例,那么这将有助于了解需求betterIt是一个多级嵌套数组,因此我无法使用查找功能使其正常工作