I have a REST API where I get search params like below.
API query
{
[
{
"state": "abc",
"country": "IN"
},
{
"state": "def",
"country": "US"
}
]
}
Mongodb schema
id | description | state | country
1 | India | abc | IN
2 | USA | def | US
I am looking for an optimized query to get the description for each API query row using one mongodb query. I am looking at nested and.
Edit: I am not looking for sorted response.
{
$and: { [
$and: [
{"state": "abc", "country": "IN"},
{"state": "def", "country": "US"}
]
] }
}
I would like to know any better approach of querying to improve query performance, a compound index for state and country field? Any pointers are highly appreciated.