0

I have a Mongo Collection like below :enter image description here

I am trying to write a query that returns the objects based on given fromS and toS in the array .

example of my array is :

[{
"from": "London",
"to":"New York"},
{
"from": "Manchester",
"to": "Paris"
}]

My expected result for giving above array to the query is to get object 5, and 6.

1 Answer 1

2

You could use the $or operator.

https://docs.mongodb.com/manual/tutorial/query-documents/#specify-or-conditions

Something like this should work:

db.myCollection.find({
    $or: [
        {"from": "London", "to": "New York"},
        {"from": "Manchester", "to":"Paris" }
    ]
});
Sign up to request clarification or add additional context in comments.

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.