python - Migrating to MongoDB: how to query GROUP BY + WHERE -


i have mysql table records of people's names , time of arrival expresed number. think of marathon. want know how many people arrived gap of time named same, so:

select name, count(*) mydb.mytable time>=100 , time<=1000 group name 

and results get:

susan, 1 john, 4 frederick, 1 paul, 2 

i'm migrating mongodb now, , using python code (so i'm asking pymongo help). tried looking information group equivalent (even when have read nosql databases worse @ kind of operation sql ones), since released new agreggate api, hjaven't been able find simple example solved group method, map-reduce method or brand new agreggate api.

any help?

there examples of on documentation, google , site.

some references:

and code:

self.db.aggregate(     # lets find our records     {"$match":{"time":{"$gte":100,"$lte":1000}}},       # lets group on name counting how many grouped documents have     {"$group":{"_id":"$name", "sum":{"$sum":1}}}  ) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -