-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
-
Query Optimization
Running $count using _id as key returns the following error:
test> db.foo.aggregate([{$count: "_id"}])
MongoServerError[Location15948]: a group's _id may only be specified once
This is because {$count: X} is just sugar for
{ $group: { _id: null, X: { $sum: 1 } } },
{ $project: {_id: 0}}
Error is confusing and could be improved