Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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
Node.js 在Mongodb中按嵌套Id查找文档_Node.js_Mongodb - Fatal编程技术网

Node.js 在Mongodb中按嵌套Id查找文档

Node.js 在Mongodb中按嵌套Id查找文档,node.js,mongodb,Node.js,Mongodb,如果我有这样的文件: [ { "_id": "5f74ee5429348348a0878822", "receivingAgentId": { "_id": "5f6bbe558b094c14103a7776", "branchId": { "_id": "5f6bbc3e8b094c14

如果我有这样的文件:

[
  {
    "_id": "5f74ee5429348348a0878822",
    "receivingAgentId": {
      "_id": "5f6bbe558b094c14103a7776",
      "branchId": {
        "_id": "5f6bbc3e8b094c14103a7770", // find by this
        "name": "Hargeisa Branch"
      },
      "name": "Hargeisa Agent",
      "description": "Hargeisa agent"
    }
  },
  {
    "_id": "5f85b23b417d46bcd9e27968",
    "receivingAgentId": {
      "_id": "5f6bbf5b8b094c14103a777b",
      "branchId": {
        "_id": "5f6bbd018b094c14103a7773",
        "name": "Ethiopia Branch"
      },
      "name": "Ethiopia Agent",
      "description": "Ethiopia agent"
    }
  }
]
如何通过子文档的\u id获取branchId中的整个子文档

我试着这样做,但没有成功

  shipments = await Shipment_new.find({
    "receivingAgentId.branchId._id": ObjectID("5f6bbe558b094c14103a7776"),
  })

你知道怎么做吗?提前感谢

但是我不想找到
receivingAgentId
,但我想找到branchId子文档。。。如果你知道我的意思吗?发货=等待发货\u new.find({“receivingAgentId.branchId.\u id:{$exists:true}})这也不起作用,谢谢你尝试任何方法!
db.collection.find( { "receivingAgentId": { "_id": ObjectID("5f6bbf5b8b094c14103a777b")} })