2
votes

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?

1
We experience the exact same symptoms, everything is fast with Mongo instance, but goes south when using CosmosDb, we have tried maxing out the RUs, it got better, but when we try with a higher count of elements, we are back with the problem. Did you find a solution? Since this was asked last February, I am hopeful you have found something. Thanks for any help you can provide.Shuryno
We have the same exprience too. On my local machine with Mongo it runs really fast within a few seconds witch Cosmos it took half an hour.Saljack

1 Answers

0
votes

Azure Cosmos DB is rate limited (See https://docs.microsoft.com/en-us/azure/cosmos-db/set-throughput ) so if you are doing some sort of large query and you have set your RU/s rate very low you will get astoundingly slow results from CosmosDB.

Try to change the RU/s rate and check if the performance varies.

Hope this helps.