MongoDB array sort not working in CosmoDB

Viewed 1502

UPDATE

The CosmoDB team confirmed that there is an issue on their said and they are already working on a fix.

More info in the comment section here: https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-introduction

ORIGINAL QUESTION

we are planning to migrate to CosmoDB but we found an issue with the $sort command. In our current MongoDB server running this query:

db.getCollection('Product').find({ 
"ProductTypeId" : ObjectId("5913546b1ba88338e4347641"), 
"SubtypeIngredients" : "5949852c1ba88344d0facbf5"
})
.skip(0).sort({ "IngredientRanks.2.Rank" : 1 }).limit(1)

We get some results but when running the same query in CosmoDB we don't get any results.

if I remove the sort command from the query, I get results from CosmoDB

The data in the collection is the same in our local db and CosmoDB.

Any help would be appreciated. Thanks!

Update:

Here is an screenshot of the actual query showing the issue.

enter image description here

2 Answers

There is no specific guarantee that CosmoDB supports all the operators and functions of MongoDB, particularly non-trivial use of the API (like chaining sort, skip , etc.). This extends to index optimization and selection as well.

This is what is mentioned in the cosmosdb website

Related