question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure CosmosDB Unexpected Pagination Behaviour

See original GitHub issue

We are using CosmosDb C# SDK
We tried both: “Microsoft.Azure.Cosmos 3.4.1”, “Microsoft.Azure.DocumentDB.Core 2.9.1 and 2.4.2”
We are getting invalid results and the main problems is the ResponseContinuation

[{“token”:null,“range”:{“min”:“05C1DFFFFFFFFC”,“max”:“FF”}}]

This started showing in one of our smaller service with only 14 documents.

In all queryes we use the folowing headers:

  • “x-ms-documentdb-query-enablecrosspartition” = true
  • “x-ms-max-item-count” = 100

Query 1:
The query is the folowing SELECT * FROM c.
We get the folowing response:

  • 7 items
  • ResponseContinuation [{"token":null,"range":{"min":"05C1DFFFFFFFFC","max":"FF"}}]

Then we use the continuation token to get the other 7 items.

Query 2:

If we modify the query to SELECT * FROM c ORDER BY c.property ASC, the order gets messed up! (responses are simplified)

  • we get the folowing result [“A”, “B”, “C”, “D”, “F”]
  • and the second query [“C”, “D”, “G”]

Query 3:
if we want to find only one item SELECT TOP 1 * FROM c WHERE c.name = @name, and the item is in the “second query result”

  • nothing and RequestContionuation {"top":1,"sourceToken":"[{\"token\":null,\"range\":{\"min\":\"05C1DFFFFFFFFC\",\"max\":\"FF\"}}]"}

This is all a really unexpected behaviour.
Why does ORDER BY, TOP even exist if we can’t even use it properly…
We can’t afford to list all data from cosmos to our server and then do ordering, expecialy on bigger containers.

Stackoverflow link: https://stackoverflow.com/questions/58876612/azure-cosmosdb-unexpected-pagination-behaviour

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bchong95commented, Dec 9, 2019

You are not allowed to mix and match continuation tokens with different queries. Please provide a console application code that reproduces the issue if there is no query or continuation token modification across continuations.

1reaction
acn-sbuadcommented, Dec 23, 2020

@Jubast you probably figured it out by now, but commenting in case someone else comes across this issue. Regarding query 3. We have solved this by checking documentQuery.HasMoreResults If there are more results, we use the continuation token, although doesn’t seem to hold any value, and we send the request again. It will then retrieve the matches from the second partition.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure CosmosDB Unexpected Pagination Behaviour
This started showing in one of our smaller service with only 14 documents. In all queryes we use the folowing headers: ... Query...
Read more >
Pagination - Azure Cosmos DB for NoSQL
This document explains criteria that Azure Cosmos DB for NoSQL's query engine uses to decide whether to split query results into multiple pages...
Read more >
Azure data factory pagination doesn't work
Coding example for the question Azure data factory pagination doesn't work. ... Azure for Students: Unexpected SQL Database Cost Quickly Draining Credits.
Read more >
Cosmos DB | Azure Proactive Resiliency Library (APRL)
Cosmos DB is by default highly resilient by running four replicas, but it is still susceptible to failures or issues with entire regions...
Read more >
Geospatial Query with Cosmos DB & Azure Data Factory
I seek to automate pagination and store each bus stop as a document in Cosmos DB. Additionally, I need automated updates, enabling delta...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found