2019-08-05

MongoDB - Retrieve only matching sub-documents

db.collection.find(

    // Match
    {
        "subdocument_to_search_within":  {
        "$elemMatch": {
                "field_within_the_subdocument": 100
            }
    }
    , "other_filter": 1
    }

    // Projection
, {
        "subdocument_to_search_within.$": 1
    }
);

No comments:

Post a Comment