Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Document DB query with "ORDER BY" stopped working suddenly

"Order by" query on Document DB suddenly stopped working on my development environment and is working fine without "Order by"

Here is the query which is not working (Use to work till yesterday and till yesterday it use to return me 70+ documents and now its returning null results(Empty array)):

SELECT * FROM c WHERE c.Category = 'test' ORDER BY c.StartDate DESC

Here is the query which is working(Currently its returning 70+ results and it use to return the same yesterday (which is not the case with the above query which is not working )):

SELECT * FROM c WHERE c.Category = 'test'

Did someone face the similar problem? What can be the solution for this?

like image 808
Adithya Sai Avatar asked Aug 16 '17 13:08

Adithya Sai


1 Answers

I found the solution to the problem. As per the documentations:

https://learn.microsoft.com/en-us/azure/cosmos-db/indexing-policies

It clearly says

"The default indexing policy sets "kind=Hash, precision=3" by default. If it is changed into "kind=Range, precision=-1". Order by on string datatype works as expected."

And i found the solution here:

https://github.com/Azure/azure-documentdb-dotnet/issues/65

Here are few more links that help you know more about Document DB Indexing

https://azure.microsoft.com/en-us/blog/order-query-results-with-azure-documentdb/

https://azure.microsoft.com/en-us/blog/update-your-documentdb-indexing-policies-online/

So i have deleted my old collection and created a new one with precision "-1".

like image 150
Adithya Sai Avatar answered Oct 25 '22 19:10

Adithya Sai