KuzyaTheBrownie
KuzyaTheBrownie

Reputation: 824

MongoDB. Find documents which contain value from array

So I have an array with some values.

How can I find all documents which contain in a specific field value from array?

For example:

Array : ["1", "2"]

Documents

{field : "1"},

{field : "2"},

{field : "3"}

I need to find:

{field : "1"},

{field : "2"}

Upvotes: 0

Views: 56

Answers (1)

erolkaya84
erolkaya84

Reputation: 1849

can you please try this?

db.inventory.find( { field: { $in: [ "1", "2"] } } )

Upvotes: 2

Related Questions