Order By Null Handling
Currently if you do an order by on a nullable value, the documents are not returned at all. Please add functionality similiar to Application Insights where you can specify if the documents with the null value appear at the beginning or end of the sort.
This feature is now complete and available.
Feng Zhu commented
Get following error when orderby with nullable property:
Exception: Underlying object does not have an 'item' field. @ at Microsoft.Azure.Cosmos.Query.OrderByItem.get_Item() @ at Microsoft.Azure.Cosmos.Query.ParallelQuery.OrderByConsumeComparer.CheckTypeMatching(IList`1 items1, IList`1 items2) @ at Microsoft.Azure.Cosmos.Query.ParallelQuery.OrderByConsumeComparer.CompareOrderByItems(IList`1 items1, IList`1 items2)
Majid Shams commented
I would call this a workaround rather than a solution.
Currently, in Cosmos DB the same query can return fewer number of items by just adding an "order by" clause to it. "order by" is supposed to change the order of the returned items only., It must not affect the number of returned items in any way.
In our application, we are using Cosmos DB as our database for a multi-tenant system. We use tenantId as the partition key to isolate tenants' documents from each other. We give users the ability to customize their document fields (aka properties) (the base document has fixed fields, but each tenant can have additional customized fields on top of that for each document type). Now, imagine a user adds a new field or removes an existing one (at the tenant level) - Should we modify indexing on the entire container for every single such changes for all tenants? (based on the new prerequisite for "order by" to work correctly, each property that needs to be used in ordered by, should be explicitly included in the indexing policy) If the properties should not be modified, then what is the point of using a so called no-schema or no-sql database? Perhaps if we use one container per tenant the handling of indexes can be more manageable, but I'm not sure how manageable it would be to handle an increasing number of containers.
Yet another sleepy "PLANNED". Any updates on this?
Majid Shams commented
Hi - I was wondering if the "next cycle" has started yet. - Thank you.
Is this issue closed
Matthew Kowalski commented
When using the ORDER BY clause, if a document does not contain the property which is being sorted on, that document will not be included in the result set.
Would it be possible to treat 'undefined' the same as 'null' when returning results sets that use an ORDER BY clause?