Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 263
fenix2222 Avatar asked Aug 23 '26 05:08

fenix2222


1 Answers

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).

like image 130
Andrew Liu Avatar answered Aug 24 '26 19:08

Andrew Liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!