Painting Blue Code
Simple, self-explanatory code snippets.
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
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment