'Mongodb Query Multiple data
Hello I have persons table
and I want to query 2 names at the same time to show their data.
I'm doing it like this
{"name":{"Jollibee", "Mcdo"}
but it is not working.
Solution 1:[1]
You can use $in operator:
collection.find({ "name": { "$in": ["Jollibee", "Mcdo"] }})
Solution 2:[2]
I am not an expert but you can use the OR condition, like
{"$or": [ { name: "Jollibee" }, { name: "Mcdo" } ] }
Solution 3:[3]
You can also use implicit $and
collection.find( { $and: [ { name: { $eq: "Jollibee" } }, { name: { $eq: "Mcdo"} } ] } )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | NeNaD |
| Solution 2 | Danilo Cacace |
| Solution 3 | buzz |
