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.

0

2 Answers 2

1

You can try using $in operator

db.collection.find({ cuisine: { $in: [ "Asian" ] }})
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.