python - Iterate through a PyMongo collection -


i need iterate through collection , values keys same name.

[     {         "_id": {             "$oid": "59b3824b44e96c07dceba8de"         },         "place": "yellow stone",         "time": "2017-09-08",         "user": "user@gmail.com",         "user_go": "yes"     },     {         "_id": {             "$oid": "59b4ea8644e96c37c43be33a"         },         "place": "yosemite",         "time": "2017-11-10",         "user": "user@gmail.com",         "user_go": "yes"     },     {         "_id": {             "$oid": "59b4ea9144e96c37c43be344"         },         "place": "devils tower",         "time": "2017-09-10",         "user": "user@gmail.com",         "user_go": "yes"     }, ] 

i'm wondering how place names from collection based on username. i've tried doing similar this:

data = db.voting.find({'user' : 'user@gmail.com'}) data = dumps(data)  parsed = json.loads(data)  x in parsed:      key,value in x.items():          print("values: {}".format(value)) 

as might guess values keys, how values keys want? i've tried place = parsed[0]['place'] returns first "place" value not values. i'm sure i'm missing obvious proving tricky wrap head around.

i reading through docs , found cursour.foreach can't find example of how use it.

x['place'] you're looking for.

for x in parsed:      place = x['place']      ... # place 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -