0

My schema looks like this:

{
  _id: "myid"
  user: [{"name":"Bob"}, {"name":"Jenny"}]
},
{
  _id: "myid2"
  user: [{"name":"John"}, {"name":"Jenny"}]
},
{
  _id: "myid3"
  user: [{"name":"John"}, {"name":"Bob"}]
}

I want to find all the documents Bob is an user of. He could be any any position in the array. Could this be done?

Thanks.

1 Answer 1

4

1) db.test.find({'user.name': 'Bob'})

2) db.test.find({'user' : { $elemMatch : {'name' : 'Bob'}}})

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.