Created
October 6, 2012 19:28
-
-
Save svkerr/3845860 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mapf='''function() { | |
...: emit(this.admin1_code, | |
...: {count:1, pop:this.population, elev:this.elevation}); | |
...: }''' | |
finalizef = '''function(key,doc) { | |
....: return { | |
....: count:doc.count, | |
....: pop: doc.pop, | |
....: mean_pop: doc.pop/doc.count, | |
....: mean_elev: doc.elev/doc.count}; | |
....: }''' | |
db.cities.reduce( | |
....: map=mapf, | |
....: reduce=reducef, | |
....: out='state_pop_elev', | |
....: query={'country_code': 'US'}, | |
....: finalize=finalizef) | |
And here is a document from the db.state_pop_elev collection: | |
{u'_id': u'WY', u'value': {u'count': 6.0, u'mean_pop': 35860.833333333336, u'mean_elev': 1679.3333333333333, u'pop': 215165.0}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I then try this:
cursor = db.state_pop_elev.find()
In [60]: for city in cursor.sort('mean_elev'):
....: print city