After I write a MongoDB aggregate command, I would like to quickly look at the number of results it returned.
Say, my query is something like this: (probably more complex)
db.zipcodes.aggregate( [{ $group :
{ _id : "$state" } }])
Then, right now I do the following to get a total count:
db.zipcodes.aggregate( [{ $group :
{ _id : "$state" }},
{'$group': {_id: null, count: {$sum: 1}}}])
Is there another quicker way to get a count of the results of a MongoDB aggregate query?
PS: I've just seen a related question: MongoDB Aggregation: How to get total records count? . Has there been any progress regarding this?
Copyright Notice:Content Author:「Phani」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/24417175/count-of-the-result-of-a-mongodb-aggregate-query