Painting Blue Code
Simple, self-explanatory code snippets.
2016-10-19
MongoDB - Count distinct values of a given field, given a query
This will retrieve the distinct values in a json string (docs object)"
db.
COLLECTION_NAME
.
distinct
( "
field_to_count
", {
query
});
This would simply retrieve the count of distinct items (not the entire object with the list of all distinct values):
db.
COLLECTION_NAME
.
distinct
( "
field_to_count
", {
query
}).
length
;
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment