Azure CosmosDB Unexpected Pagination Behaviour
See original GitHub issueWe 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:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
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.
@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.