0

I have a MongoDB database structure that looks something like this.

{
    "peopleholder": {
        "people": [
            {
                "otherdata": "asdf",
                "name": "joe"
            },
            {
                "otherdata": "asdf",
                "name": "bob"
            }
        ]
    }
}

Now, I'm trying to construct a search query to select all people who have name "bob", right?

So, I've tried some things, looking at the $all suggestion, and come up with...

{
    "peopleholder": {
        "people": {
            "$all": [
                {
                    "name": "bob"
                }
            ]
        }
    }
}

I've also tried it with people just equal to {"name": "bob"}, as that appears to be shorthand.

1 Answer 1

1

This should do it:

{ "peopleholder.people.name": "bob"}

Source Mongodb docs

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

2 Comments

Worked! Thank you!
Don't forget that this query will be case sensitive.

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.