Reputation: 77
I am new to mongoDB. I am using pymongo.
Here I have an example list of favorite colors stored in a mongoDB collection named colors
:
mylist = [
{"name": "Amy", "color": "Red"},
{"name": "Hannah", "color": "Blue"},
{"name": "Michael", "color": "Green"},
{"name": "Sarah", "color": "Orange"}
]
Using the search query how do I take the value "color" using query searching using a name like Michael? So the output would be like:
Green
Upvotes: 1
Views: 117
Reputation: 9268
You can do it something like this:
Assuming that name is unique, you can try this:
db.colors.find_one({"name" : "Michael"})["color"]
You can read more about find_one
here
Upvotes: 1