fenix2222
fenix2222

Reputation: 4730

Cannot get paging working in Azure DocumentDB

For some reason I cannot get paging properly working for Azure DocumentDB

Here is a code snippet

var finalResults = new List<MyResult>();
// Here I am setting max page size to be 10
var options = new FeedOptions { MaxItemCount = 10 };
var query = client.CreateDocumentQuery<MyResultItem>(collection.SelfLink, options)
                  .SelectMany(r => r.Results)
                  .Where(r => r.Result > 75)
                  .Select(r => r)
                  .AsDocumentQuery();
 // it only works 1 iteration and next iteration I always get HasMoreResults = false
 // if I set MaxItemCount = 20, then I get 20 only
 while (query.HasMoreResults)
 {
     var pagedResults = query.ExecuteNextAsync<MyResult>().Result;
     foreach (var pagedResult in pagedResults)
     {
         finalResults.Add(pagedResult);
     }
 }

No matter what value I set for MaxItemCount, it will only get that many items and will not get the next batch, so I get query.HasMoreResults always returning false on the second iteration. I cannot find where the problem is

Update:

Json structure is as follows:

.NET object name MyResultItem

{
    Id: "xxxxxxxxxxxxxxxxxxxxx",
    Name: "xxxxxxxxxxxxxxx",
    Results: [
        { Id: 1, Result: 123 },
        { Id: 2, Result: 40 },
        { Id: 3, Result: 75 }
    ]
}

I am trying to get a flat list of "Results" where Result > 75

Upvotes: 3

Views: 1779

Answers (1)

Andrew Liu
Andrew Liu

Reputation: 8119

This appears to be a bug w/ DocumentDB; the continuation token misbehaves for selectmany (and joins) when the number of elements in the child array is less than the request's page size.

I found a similar thread on the MSDN forums on this subject.

A fix is currently being worked on.

In the meantime, you can try to work around this issue by increasing the page size (e.g. set it to the max of 1,000).

Upvotes: 1

Related Questions