0

For example, if these are the documents:

{
    "_id": 1,
    "test_array": [1,2,3,5]
},
{
    "_id": 2,
    "test_array": [4,5]
},
{
    "_id": 1,
    "test_array": [1,2,3]
}

And I want to get all the documents which "test_array" includes 4 or 5 (aka doc 1 and 2).
Is there a simple query for it?

TheZadok42
  • 147
  • 1
  • 9

1 Answers1

0

$in

the $in operator selects the documents where the value of a field equals any value in the specified array

so just try

db.collection.find({
  test_array: {
    $in: [
      4,
      5
    ]
  }
})

mongoplayground

Mohammad Yaser Ahmadi
  • 4,664
  • 3
  • 17
  • 39