2017-08-13

MongoDB - Sub-document filtering to return only desired sub-documents

db.COLLECTION_NAME.find(

    // Filtering. match
    {
        "FIELD_TO_FILTER_BY": FILTER_VALUE
    }

    // Projection
    , {
        ARRAY_OF_SUBDOCS:{
            $elemMatch:{"SUB_DOC_FIELD": FILTER_VALUE }
        }
    }
);

No comments:

Post a Comment