0

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.

3 Answers 3

1

You can use $in operator:

collection.find({ "name": { "$in": ["Jollibee", "Mcdo"] }})
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. this works. May I ask why $and is not working?
Because your query means that you try to find document were the name property is equal to the object {"Jollibee", "Mcdo"}, and that is not valid. If you want to find multiple values for a property, you can either use $or operator for each value explicitly, or $in operator that takes an array of all the values that you are interested.
0

I am not an expert but you can use the OR condition, like

{"$or":  [ { name: "Jollibee" }, { name: "Mcdo" } ] }

Comments

0

You can also use implicit $and

collection.find( { $and: [ { name: { $eq: "Jollibee" } }, { name: { $eq: "Mcdo"} } ] } )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.