Reputation: 3325
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?
Upvotes: 1
Views: 3468
Reputation: 171
db.zipcodes.aggregate( [{ $group :
{ _id : "$state" } },
{
$count: "total"
}
])
Upvotes: 1
Reputation: 3325
One workaround I found so far is to use a MongoDB GUI such as Robomongo. It reports the size of the Result.
Upvotes: 0