Reputation: 327
I have following json object:
{
"id": "9df7d70e-1b07-4080-ac9e-964332c93a89",
"name": "some name",
"ranking": {
"A": 1,
"B": 2,
}
}
I want to get items sorted by ranking depending on the key A or B using pagination.
The query I am using for this:
SELECT * FROM c WHERE ... ORDER BY c.ranking['A'] ASC
Pagination params:
FeedOptions feedOptions = new FeedOptions()
{
MaxItemCount = cosmosDbSettings.PageResultsCount,
RequestContinuation = continuationToken,
EnableCrossPartitionQuery = true
};
Trigger cosmos db:
var docQuery = documentClient.CreateDocumentQuery<dynamic>(
UriFactory.CreateDocumentCollectionUri(cosmosDbSettings.DatabaseId, collectionId),
new SqlQuerySpec(query, sqlParameters),
feedOptions)
.AsDocumentQuery();
var results = new PagedResources();
List<dynamic> resources = new List<dynamic>();
var queryResult = await docQuery.ExecuteNextAsync();
while (queryResult.Count == 0 && docQuery.HasMoreResults)
{
queryResult = await docQuery.ExecuteNextAsync();
}
if (!queryResult.Any())
{
return results;
}
For the first and the second page it works OK, then suddenly some items are missing in response.
At the end of the token filter is appears
filter":"c.ranking[\"A\"] >= 2"
Whole token:
[{"compositeToken":{"token":"+RID:~oClCAPq5X0KLAAAAAAAAAA==#RT:2#TRC:20#RTD:GQD5+RFVofBwed+BlCvhBMAU#ISV:2#IEO:65551#FPC:AgEAAAAcAHMAwP1gHxAAUgB4ABgAEQAAGDaA4wAcAABgwkM=","range":{"min":"","max":"05C1DFFFFFFFFC"}},"orderByItems":[{"item":5}],"rid":"oClCAPq5X0KMAAAAAAAAAA==","skipCount":0,"filter":"c.ranking[\"A\"] >= 2"}]
Maybe I am missing something, any help would be appreciated!
Upvotes: 0
Views: 256
Reputation: 15583
Please make sure you drain all the query results (source):
while (docQuery.HasMoreResults)
{
var queryResult = await docQuery.ExecuteNextAsync();
resources.AddRange(queryResult);
}
return resources;
Also the content of the continuation token is opaque, whatever it contains is meant for the query engine to use on the next time you want to resume. If you drain all the results (as I showed), it will be null
.
Upvotes: 1