0
  {
    "id": "1505036191456227329",
    "materialList": [
        {
            "id": "1505035441229459457",
            "model": "",
            "parentId": "0",
        
        },
          {
            "id": "1505035441229459458",
            "model": "",
            "parentId": "1505035441229459457",
        
        }, {
            "id": "1505035441229459459",
            "model": "",
            "parentId": "1505035441229459457",
        
        },{
            "id": "1505035441229459460",
            "model": "",
            "parentId": "1505035441229459459",
        
        }
    ]

}

this is my data,I want to find all sub data IDS with ID 1505035441229459457 under the materiallist。

The result of the query is 1505035441229459458,1505035441229459459,1505035441229459460

tengger
  • 1
  • 1
  • You can only query in flat document by using [graphLookup](https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/) – YuTing Mar 23 '22 at 05:59

1 Answers1

0

You will have to use $elemMatch for this.

Ex -> db.collection.find( { materialList: { $elemMatch: {id: 1505035441229459457 } } })