Fetch only matching nested Array document only

Please read Formatting code and log snippets in posts and update your sample documents, code and expected result.

If you were only interested in the first element you could use a projection that repeats your $elemMatch

If you are interested in all elements that match, which your expect result shows, it is a little bit more complicated. You need a $filter projection such as:

{ "tags" : { "$filter" : {
    "input" : "$tags" ,
    "cond" : {
        "$and" : [
            { "$eq" : [ "$$this.tag_name" , "Testnew" ] } ,
            { "$eq" : [ "$$this.status" , true ] }
        ]
    }
} } }
1 Like