1

If I would like to query if a field in an array I can do this

students.find({'name':{$in:['Mark','Jerry']}})

But what if I would like to find a string is in a array of an mongodb object like

{
  "name":"Jerry",
  "classes":["math","english","nature"]
}

How do I query if a class name "science" in classes array of this mongodb object?

Thanks

1 Answer 1

1

It's just:

db.students.find({'classes': 'science'})
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.