0

I have collection in mongodb like below:

{   
  "_id": "xyz",
  "title" : "title+",
  "foodBeverage" : [
    "Expert 1"
],
"cuisine" : [
    "Afghan",
    "American",
    "Asian",
    "Bistro"
  ]
}

I want to with below array:

var arr1 = ["Asian"];

I want query to match using arr1. Like if value in arr1 exist in collection with cuisine, then return result.

Hope you get how I want filter.

Could any one assist.

thanks in advance.

rohit13807
  • 605
  • 8
  • 19

2 Answers2

1

You can try using $in operator

db.collection.find({ cuisine: { $in: [ "Asian" ] }})
Ashwini singh
  • 51
  • 1
  • 7
1

You have to use $in in your query, like this :

db.test.find(
  {cuisine:
    {$in : ["Asian",...]   <= here your arr1
    }
  }
)

It will return your document if any of the 'cuisine' values matches with any of your arr1 values

matthPen
  • 4,253
  • 1
  • 16
  • 16