Details
-
Improvement
-
Resolution: Done
-
Blocker - P1
-
None
-
*Location*: http://docs.mongodb.org/manual/tutorial/aggregation-zip-code-data-set/
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.86 Safari/537.36
*Referrer*: http://docs.mongodb.org/manual/core/aggregation-pipeline/
*Screen Resolution*: 1440 x 900
*repo*: docs
*source*: tutorial/aggregation-zip-code-data-set
*Location*: http://docs.mongodb.org/manual/tutorial/aggregation-zip-code-data-set/ *User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.86 Safari/537.36 *Referrer*: http://docs.mongodb.org/manual/core/aggregation-pipeline/ *Screen Resolution*: 1440 x 900 *repo*: docs *source*: tutorial/aggregation-zip-code-data-set
Description
Hello.
About the example "Return Average City Population by State" I spent a lot of time figuring out why the query was so complex.
I had to analyze the dataset to see that cities can have the same name in the same state. Maybe it is obvious for americans but not really for foreign people like me ![]()
I think it should me mentioned somewhere that we need to group on state AND cities because 2 cities can have the same name, in the same state.
Else, the simple following request would be enough:
db.collection.aggregate([{$group: { _id: "$state", average: {$avg: "$pop" }}}])
Michel