1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.