Mongo Playground

Configuration

[{"_id":"1","name":"sanggiyo","gender":"Male","children":[{"name":"tono","gender":"Male","children":[{"name":"anton","gender":"male","children":[],"_id":"4"}],"_id":"2"},{"name":"rin","gender":"Female","children":[],"_id":"3"}],"createdAt":"2022-04-17T11:14:00.648Z","updatedAt":"2022-04-17T11:14:16.277Z","__v":0}]

Query

db.collection.aggregate([{$match:{$or:[{"_id":"1"},{"children._id":"1"},{"children.children._id":"1"}]}},{"$replaceRoot":{"newRoot":{"$first":{"$filter":{"input":"$children","as":"item","cond":{$eq:["$$item._id","3"]}}}}}}])

Result