MaxItemCount and FeedIterator.HasMoreResult retrieved less items than expected.
See original GitHub issueDescribe the bug We use QueryRequestOptions.MaxItemCount and FeedIterator.HasMoreResult to retrieve the specific number of items back like below sample code:
while ((requestOption.MaxItemCount <= 0 || list.Count < ro.MaxItemCount) && feedIterator.HasMoreResults)
{
FeedResponse<T> feed = await feedIterator.ReadNextAsync();
foreach (var item in feed)
{
list.Add(item);
}
}
This should retrieve the number of MaxItemCount back. It works for most cases and I test locally it also works welll.
But in PROD env for some cases, we only retrieve small amount of item results back when there are far more item result that meet the query filter condition that exist in the database. For our case, MaxItemCount is 150, item that meet the query filter condition is more than 50000, only retrieve 95 item back for lot of request.
To Reproduce Can’t reprouce locally.
Set MaxItemCount = 150, data that meet the query condition is more than this
Expected behavior Retrieve 150 items back
Actual behavior only less than 150 items are retrieved back.
Environment summary SDK Version: 3.31.0 OS Version Windows
Issue Analytics
- State:
- Created 3 months ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
@adityasa Thanks for the response. However, looking at the examples I fail to understand the difference between @blankor1’s code and the provided code sample in the link you provided.
Let me try to rephrase the question to make it clearer: I wrote a code snippet from the link you provided above and made some slight modifications:
Questions:
response.ContinuationToken
and callcontainer.GetItemQueryIterator
multiple times in order to iterate through all the Famility entities?Based on the (limited) code snippet above, the behavior is by design. If all results need to be fetched for a query, continuation token must be fully drained in the application code. Here’s a resource that explains this in cosmos db: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/query/pagination
Here’s a code sample in .NET sdk that shows how to do this: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos.Samples/Usage/Queries/Program.cs#L294
Specifically, please note that pagination loop for the purposes of draining the continuation token needs to be implemented based on HasMoreResults property and rather should not depend on MaxItemCount, # of documents returned in the response etc.
Hope this helps.