Reputation: 165
We are migrating from mongoDB to CosmoDB using the Mongo API. We have encountered the following difference in query behavior around sorting.
Using the CosmoDB mongo API sorting by a field removes all documents that don't have that field. Is it possible to modifying the query to including the nulls to replicate the mongo behavior?
For example if we have the following 2 documents
[{
"id":"p1",
"priority":1
},{
"id":"p2"
}]
performing:
sort({"priority":1})
cosmoDB will return a single result 'p1'.
mongo will return both results in the order 'p2', 'p1', the null documents will be first.
Upvotes: 3
Views: 759
Reputation: 580
I had the same problem and got solved after some reading Refer the document... You have to update the indexing policy of the container to change the default way of Cosmos DB sorting!
Upvotes: 1
Reputation: 28007
As far as I know, the null value will not include in the query result sort scan.
Here is a workaround, you could set a not exists field in the sort method to force the engine scan all the data.
Like this:
db.getCollection('brandotestcollections').find().sort({"test": 1, "aaaa":1})
The result is like this:
Upvotes: 1