Table of Contents

Class FeedIterator

Namespace
Microsoft.Azure.Cosmos
Assembly
Microsoft.Azure.Cosmos.Client.dll

Cosmos Result set iterator that keeps track of the continuation token when retrieving results form a query.

public abstract class FeedIterator : IDisposable
Inheritance
FeedIterator
Implements
Inherited Members
Extension Methods

Examples

Example on how to fully drain the query results.

QueryDefinition queryDefinition = new QueryDefinition("select c.id From c where c.status = @status")
              .WithParameter("@status", "Failure");
using (FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
    queryDefinition))
{
    while (feedIterator.HasMoreResults)
    {
        // Stream iterator returns a response with status code
        using(ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            // Handle failure scenario
            if(!response.IsSuccessStatusCode)
            {
                // Log the response.Diagnostics and handle the error
            }
        }
    }
}

Constructors

FeedIterator()

protected FeedIterator()

Properties

HasMoreResults

Tells if there is more results that need to be retrieved from the service

public abstract bool HasMoreResults { get; }

Property Value

bool

Examples

Example on how to fully drain the query results.

QueryDefinition queryDefinition = new QueryDefinition("select c.id From c where c.status = @status")
              .WithParameter("@status", "Failure");
using (FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
    queryDefinition))
{
    while (feedIterator.HasMoreResults)
    {
        // Stream iterator returns a response with status code
        using(ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            // Handle failure scenario
            if(!response.IsSuccessStatusCode)
            {
                // Log the response.Diagnostics and handle the error
            }
        }
    }
}

Methods

Dispose()

Releases the unmanaged resources used by the FeedIterator and optionally releases the managed resources.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the FeedIterator and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

ReadNextAsync(CancellationToken)

Get the next set of results from the cosmos service

public abstract Task<ResponseMessage> ReadNextAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

Task<ResponseMessage>

A query response from cosmos service

Examples

Example on how to fully drain the query results.

QueryDefinition queryDefinition = new QueryDefinition("select c.id From c where c.status = @status")
              .WithParameter("@status", "Failure");
using (FeedIterator feedIterator = this.Container.GetItemQueryStreamIterator(
    queryDefinition))
{
    while (feedIterator.HasMoreResults)
    {
        // Stream iterator returns a response with status code
        using(ResponseMessage response = await feedIterator.ReadNextAsync())
        {
            // Handle failure scenario
            if(!response.IsSuccessStatusCode)
            {
                // Log the response.Diagnostics and handle the error
            }
        }
    }
}