c00p3r.web
c00p3r.web

Reputation: 848

MongoDB: multiple $in on the same field

I want to query mongoDB field for data that is '$in' two lists (arrays) kinda:

{user: {$in: [<array1>]} AND user: {$in: [<array2>]}}

so the query returns only those 'users' that present in both arrays.

I feel this isn't right:

 {user: {$in: [<array1>], [<array2>]}}

Any ideas?

Upvotes: 0

Views: 2028

Answers (1)

DhruvPathak
DhruvPathak

Reputation: 43265

Either you can use the $AND operator.

http://docs.mongodb.org/manual/reference/operator/query/and/

{'$AND':[ {'user':{$in: [<..array1..>]} },{'user':{$in: [<..array2..>] }  }] }

Upvotes: 4

Related Questions