This would be the easier way to do it using aggregate
:
db.contest.aggregate([
{"$group" : {_id:"$province", count:{$sum:1}}}
])
More Related Contents:
- Retrieve only the queried element in an object array in MongoDB collection
- Update MongoDB field using value of another field
- Does MongoDB’s $in clause guarantee order
- Multiple join conditions using the $lookup operator
- Conditional $sum in MongoDB
- Aggregate $lookup Total size of documents in matching pipeline exceeds maximum document size
- Average Aggregation Queries in Meteor
- exclude fields in $lookup aggregation
- Find duplicate records in MongoDB
- $unwind empty array
- How to sum every fields in a sub document of MongoDB?
- Add some kind of row number to a mongodb aggregate command / pipeline
- Mongo sort on a calculated condition
- Find all duplicate documents in a MongoDB collection by a key field
- MongoDB sort documents by array elements
- MongoDB: Calculate dwell time between every status value change
- MongoDB: how to parse date in 3.6 mongoDb version?
- Using stored JavaScript functions in the Aggregation pipeline, MapReduce or runCommand
- MongoDB – The argument to $size must be an Array, but was of type: EOO / missing
- How to flatten a subdocument into root level in MongoDB?
- convert iso date to timestamp in mongo query
- Remove Duplicates from MongoDB
- Using $slice operator to get last element of array
- How to access overall document count during arithmetic aggregation expression
- How to deal with the timezone issue when storing dates in utc using mongod?
- Sum in nested document MongoDB
- MongoDB to Use Sharding with $lookup Aggregation Operator
- Mongodb, aggregate query with $lookup
- mongodb aggregate query isn’t returning proper sum on using $sum
- Return the last “true” value for each group