I'm using the MongoDB api to access a CosmosDb on Azure. I have a collection of a few thousand documents.
They are shaped like this:
{
"_id" : ObjectId("5b4f574ac2100c890805a7d8"),
"id" : 12,
"name" : "Spotted Owl",
"overview" : "Some Overview text",
"family" : "Barn Owls, Typical Owls (Tytonidae & Strigidae)",
"latinName" : "Strix occidentalis"
}
I have the need to query the documents using a potentially large number of "id" in an $in query. The query is simple,
// The "$in" list can be 1000 items long.
db.MyCollection.find({"id": {$in: [1,2,3,4,5,6...]}})
I have a non-unique index( that probably should be unique ):
{
"id" : 1
}
The result is that the query with 1000 items takes 20 seconds or more to return. If I simply get all of the documents with :
db.MyCollection.find({});
The results take less than a second to return.
Furthermore, if I run the same tests against my a local native Mongo instance, both queries return in under a second.
What am I missing on the Azure/CosmosDb side that could be causing all of this slowdown?