1
votes

Is it possible, using the DocumentDB .NET SDK, to make run an asynchronous query against the DB that returns all matching documents?

The answer answer to this StackOverflow question: Querying Azure DocumentDB with ExecuteNextAsync returns fewer than MaxItemCount indicates that:

There are limits for how long a query will execute on DocumentDB.
...
If these limits are hit, then a partial set of results may be returned.

I know that it's possible to overcome the above mentioned limit by iterating over paged results like so: (source)

List<Family> families = new List<Family>();

FeedOptions options = new FeedOptions { MaxItemCount = 1 };

var query = client.CreateDocumentQuery<Family>(collectionLink, options).AsDocumentQuery();

while (query.HasMoreResults)
{
    foreach (Family family in await query.ExecuteNextAsync())
    {
        families.Add(family);
    }
}

My question is - Is this loop necessary? Might there be a more elegant way to tell the SDK to return all results available (without paging)?

1
I never use it because I manage my own paging with a lazy interface but I thought the toArray() method did what are asking for.Larry Maccherone
Can you try that using CreateStoredProcedureQueryy. Like client.CreateStoredProcedureQuery(collectionLink,"Select * from myColleciton");.vikscool

1 Answers

2
votes

The loop you have is the best way to perform enumerating across multiple requests since there is a bounded time execution on each request in DocumentDB.

You could wrap this code in an extension method to make it handy.

This is a good suggestion for DocumentDB team to add this support - https://github.com/Azure/azure-documentdb-dotnet/issues