1

I have my mongo data as follows: group:{"name":group1, members: [{"id":1,"name": "member1"},{"id":2,"name": "member2"}]}

I would like to this collection 'group' to fetch all the groups where a person with 'id=1' is part of. The complication is that 'members' is a collection.

1 Answer 1

2

You can do it with simple find:

db.groups.find({'members.id':personId})

From documentation: If the array holds embedded documents, you can query for specific fields in the embedded documents using dot notation.

The query will check each element in the array for matching specific field and if there is any match the whole document will be returned.

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.