OrderBy query result is not ordered from cosmos db container using SQL API

Habeebuddin, Syed 1 Reputation point
2022-11-11T10:47:57.353+00:00

Steps:

  1. I'm querying the cosmos db container with an order by query and getting the results in a proper order.
  2. Now , I'm updating the one of the array node in the documents of the same container.
  3. Again when I'm querying the container with the same order by query , the results are not in order.

Explanation :
A document in the container looks like:

{
"message": "A Sample Message",
"eventType": "TicketApproved",
"readBy": [
"1d2b3d74-9252-4796-bb3c-e726d565840a",
"6dfcf933-4a7d-4242-99ad-18e459d32860"
],
"deletedFor": [
"0e9ed454-97ea-4f00-ab42-8f41a4052164",
"b914b150-2617-403e-bee3-ed527d43d5ce"
],
"ttl": 2592000,
"id": "6733c80b-0cb2-4ddc-b7cf-065a62c054e9",
"createdAt": "2022-10-19T13:30:58.869829+05:30",
"updatedAt": "2022-10-19T13:30:58.8698879+05:30"
}

Whenever I'm retrieving these documents with an "Order by createdAt" , the result is a proper ordered list of documents , but when I update the documents in the container and then retrieve the documents with an "Order by createdAt" query the result is unordered.

The Queries I tried are:
All these queries are resulting the ordered list of dcouments untill I update the documents. Once I update a few documents from the result set , those are not part of the result set when I run the query again.

var query = sampleContainer.GetItemLinqQueryable<SampleData>(true)
.Where(x => x.Id != null &&
events.Contains(x.EventType) &&
!x.DeletedFor.Contains(userId))
.OrderByDescending(x => x.CreatedDate);
.Skip(0).Take(25);

var query = "Select * from c where c.deletedFor NOT IN('{id}') and c.eventType IN('TicketApproved') Order By c.createdAt desc OFFSET 0 LIMIT 25";

var query = Select c.message,c.eventType,c.readBy,c.deletedFor,c.ttl,c.id,c.createdAt,c.updatedAt from c JOIN d IN c.deletedFor where d != '{id}' and c.eventType IN('TicketApproved') Order By c.createdAt desc OFFSET 0 LIMIT 25;

Please let me know If anything I'm missing here.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,901 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.