Depending on your use case, MongoDB v3.4 provides an aggregation pipeline operator called $graphLookup. The aggregation operator is able to perform a recursive search on a collection. See more definiton on $graphLookup definition.

Using your documents hierarchy and values above as examples, you could try running below aggregation:

db.collectionName.aggregate([ {$unwind:{ path:"$childrenIdList", preserveNullAndEmptyArrays: true} }, {$graphLookup:{ from:"collectionName", startWith:"$_id", connectFromField:"_id", connectToField:"childrenIdList", as:"myparents", restrictSearchWithMatch: {"_id"}} }, {$match: {"_id": 7 } }, {$group:{ _id:"$_id", parents:{$addToSet:"$myparents._id"} }} ]);

The above should return result as below:

{ "_id" : 7, "parents" : [ [ 1, 2, 4 ] ] }

Having said that, if you have a large collection the above query may not be performant as you'll be performing $unwind on each documents and won't be able to utilise indexes. As suggested by others, you should re-consider your document model structure. See Data Models Tree Structures. Optimise based on your application logic and querying use case, and let the flexible document schema follow.