0

Given the below example record, how can I find all users that belong to at least one group from an arbitrary set of groups to query against? For example, find all users that belong to any one of the following groups - 1, 10, 43. I'm looking for a generalized solution. I know I can build out an or query but is there a more efficient way to handle this?

> db.users.findOne()
{
    "_id" : ObjectId("508f477aca442be537000000"),
    "name" : "Some Name",
    "email" : "[email protected]",
    "groups" : [
        1,5,10
    ]
}
2
  • Whats the problem with $or query.. its a perfect way to do it.. Commented Nov 6, 2012 at 5:16
  • There's nothing wrong with it. It just requires a loop to build the query whereas I can just drop in my array in the method outlined in the answer below without any additional work. In any case, thanks for your help! Commented Nov 6, 2012 at 7:39

1 Answer 1

3

{ groups: {$in: [1, 10, 43]} }

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.