TIMEX
TIMEX

Reputation: 272214

How would I execute this query in MongoDB?

Let's say I have a collection of "rooms". Each room is a document that looks like this:

room = {
        perms: [ { user:"matt", visible: 1 },
                 { user:"alex", visible: 0 },
                 { user:"jennifer", visible: 1 },
};

In MongoDB, how would I find rooms that have a permission of user=alex and visible=0 ?

Upvotes: 1

Views: 124

Answers (1)

Sarah Roberts
Sarah Roberts

Reputation: 860

If I understand your question correctly, the $elemMatch operator should do what you want:

{ "perms": { "$elemMatch": { "user": "alex", "visible": 0 } } }

Upvotes: 1

Related Questions