Share via


DocumentClient.ReadDocumentFeedAsync Method

Definition

Overloads

ReadDocumentFeedAsync(String, FeedOptions, CancellationToken)

Reads the feed (sequence) of documents for a specified collection from the Azure Cosmos DB service. This takes returns a ResourceResponse<TResource> which will contain an enumerable list of dynamic objects.

ReadDocumentFeedAsync(Uri, FeedOptions, CancellationToken)

Reads the feed (sequence) of documents for a collection as an asynchronous operation from the Azure Cosmos DB service.

ReadDocumentFeedAsync(String, FeedOptions, CancellationToken)

Reads the feed (sequence) of documents for a specified collection from the Azure Cosmos DB service. This takes returns a ResourceResponse<TResource> which will contain an enumerable list of dynamic objects.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.FeedResponse<dynamic>> ReadDocumentFeedAsync (string documentsLink, Microsoft.Azure.Documents.Client.FeedOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadDocumentFeedAsync : string * Microsoft.Azure.Documents.Client.FeedOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.FeedResponse<obj>>
override this.ReadDocumentFeedAsync : string * Microsoft.Azure.Documents.Client.FeedOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.FeedResponse<obj>>
Public Function ReadDocumentFeedAsync (documentsLink As String, Optional options As FeedOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of FeedResponse(Of Object))

Parameters

documentsLink
String

The SelfLink of the resources to be read. E.g. /dbs/db_rid/colls/coll_rid/docs/

options
FeedOptions

(Optional) The request options for the request.

cancellationToken
CancellationToken

(Optional) A CancellationToken that can be used by other objects or threads to receive notice of cancellation.

Returns

A System.Threading.Tasks containing a ResourceResponse<TResource> containing dynamic objects representing the items in the feed.

Implements

Exceptions

If documentsLink is not set.

This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a Document are:

StatusCodeReason for exception
404NotFound - This means the resource feed you tried to read did not exist. Check the parent rids are correct.
429TooManyRequests - This means you have exceeded the number of request units per second. Consult the DocumentClientException.RetryAfter value to see how long you should wait before retrying this operation.

Examples

int count = 0;
string continuation = string.Empty;
do
{
    // Read the feed 10 items at a time until there are no more items to read
    FeedResponse<dynamic> response = await client.ReadDocumentFeedAsync("/dbs/db_rid/colls/coll_rid/docs/",
                                                    new FeedOptions
                                                    {
                                                        MaxItemCount = 10,
                                                        RequestContinuation = continuation
                                                    });

    // Append the item count
    count += response.Count;

    // Get the continuation so that we know when to stop.
     continuation = response.ResponseContinuation;
} while (!string.IsNullOrEmpty(continuation));

Remarks

Instead of FeedResponse{Document} this method takes advantage of dynamic objects in .NET. This way a single feed result can contain any kind of Document, or POCO object. This is important becuse a DocumentCollection can contain different kinds of documents.

See also

Applies to

ReadDocumentFeedAsync(Uri, FeedOptions, CancellationToken)

Reads the feed (sequence) of documents for a collection as an asynchronous operation from the Azure Cosmos DB service.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.FeedResponse<dynamic>> ReadDocumentFeedAsync (Uri documentsUri, Microsoft.Azure.Documents.Client.FeedOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadDocumentFeedAsync : Uri * Microsoft.Azure.Documents.Client.FeedOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.FeedResponse<obj>>
override this.ReadDocumentFeedAsync : Uri * Microsoft.Azure.Documents.Client.FeedOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.FeedResponse<obj>>
Public Function ReadDocumentFeedAsync (documentsUri As Uri, Optional options As FeedOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of FeedResponse(Of Object))

Parameters

documentsUri
Uri

the URI for the documents.

options
FeedOptions

The request options for the request.

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

The task object representing the service response for the asynchronous operation.

Implements

Applies to