When using MongoDB aggregation - How to filter out results with no aggregated children? When using MongoDB aggregation - How to filter out results with no aggregated children? mongoose mongoose

When using MongoDB aggregation - How to filter out results with no aggregated children?


Use a $match stage after the $lookup

{ "$match": { "birds": { "$ne": [] }}}

Since there is no barrier for the parent collection it returns all the documents. So to filter out the documents (things) which do not contain atleast one birds you have to use $match stage in the parent collection