Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何使用mongo函数匹配数组中的objectid?_Arrays_Match - Fatal编程技术网

Arrays 如何使用mongo函数匹配数组中的objectid?

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

我们可以在两个数组中匹配objectid,使用mongo聚合组合数据,还是需要使用承诺

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是一个多级嵌套数组,因此我无法使用查找功能使其正常工作