urig
urig

Reputation: 16831

Is it possible to asynchronously query DocumentDB for all documents (i.e no paging)?

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

Upvotes: 1

Views: 1299

Answers (1)

Shireesh Thota
Shireesh Thota

Reputation: 303

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

Upvotes: 2

Related Questions