Table of Contents

Class FeedOptions

Namespace
Microsoft.Azure.Documents.Client
Assembly
Microsoft.Azure.Documents.Client.dll

Specifies the options associated with feed methods (enumeration operations) in the Azure Cosmos DB service.

public sealed class FeedOptions
Inheritance
FeedOptions
Inherited Members
Extension Methods

Remarks

Used to manage query and ReadFeed execution. Can use FeedOptions to set page size (MaxItemCount)

Constructors

FeedOptions()

Initializes a new instance of the FeedOptions class for the Azure Cosmos DB service.

public FeedOptions()

Properties

ConsistencyLevel

Gets or sets the consistency level required for the feed (query/read feed) operation in the Azure Cosmos DB service.

public ConsistencyLevel? ConsistencyLevel { get; set; }

Property Value

ConsistencyLevel?

The consistency level required for the request.

Examples

This example uses FeedOptions to override the consistency level to Eventual.

Document doc = client.ReadDocumentFeedAsync(documentLink, new FeedOptions { ConsistencyLevel = ConsistencyLevel.Eventual });

Remarks

Azure Cosmos DB offers 5 different consistency levels. Strong, Bounded Staleness, Session, Consistent Prefix and Eventual - in order of strongest to weakest consistency. ConnectionPolicy

Azure Cosmos query/DB feed operations may be retrieved from many partitions, each accessed across many round trips. The consistency level is honored only within a partition and round trip.

While this is set at a database account level, Azure Cosmos DB allows a developer to override the default consistency level for each individual request.

See Also

DisableRUPerMinuteUsage

Gets or sets the DisableRUPerMinuteUsage option for the current query in the Azure Cosmos DB service.

public bool DisableRUPerMinuteUsage { get; set; }

Property Value

bool

Remarks

DisableRUPerMinuteUsage is used to enable/disable Request Units(RUs)/minute capacity to serve the query if regular provisioned RUs/second is exhausted.

EnableCrossPartitionQuery

Gets or sets a value indicating whether users are enabled to send more than one request to execute the query in the Azure Cosmos DB service. More than one request is necessary if the query is not scoped to single partition key value.

public bool EnableCrossPartitionQuery { get; set; }

Property Value

bool

Option is true if cross-partition query execution is enabled; otherwise, false.

Examples

// Enable cross partition query.
var queryable = client.CreateDocumentQuery<Book>(
    collectionLink, new FeedOptions { EnableCrossPartitionQuery = true }).Where(b => b.Price > 1000);

Remarks

This option only applies to queries on documents and document attachments.

EnableLowPrecisionOrderBy

Gets or sets the option to enable low precision order by in the Azure Cosmos DB service.

public bool? EnableLowPrecisionOrderBy { get; set; }

Property Value

bool?

The option to enable low-precision order by.

EnableScanInQuery

Gets or sets the option to enable scans on the queries which couldn't be served as indexing was opted out on the requested paths in the Azure Cosmos DB service.

public bool? EnableScanInQuery { get; set; }

Property Value

bool?

Option is true if scan on queries is enabled; otherwise, false.

Examples

// Enable scan when Range index is not specified.
var queryable = client.CreateDocumentQuery<Book>(
    collectionLink, new FeedOptions { EnableScanInQuery = true }).Where(b => b.Price > 1000);

JsonSerializerSettings

Gets or sets the JsonSerializerSettings for the current request used to deserialize the document. If null, uses the default serializer settings set up in the DocumentClient.

public JsonSerializerSettings JsonSerializerSettings { get; set; }

Property Value

JsonSerializerSettings

MaxBufferedItemCount

Gets or sets the maximum number of items that can be buffered client side during parallel query execution in the Azure Cosmos DB service. A positive property value limits the number of buffered items to the set value. If it is set to less than 0, the system automatically decides the number of items to buffer.

public int MaxBufferedItemCount { get; set; }

Property Value

int

The maximum count of items that can be buffered during parallel query execution.

Examples

var queryable = client.CreateDocumentQuery<Book>(collectionLink, new FeedOptions { 
MaximumBufferSize = 10, MaxDegreeOfParallelism = 2 });

Remarks

This is only suggestive and cannot be abided by in certain cases.

MaxDegreeOfParallelism

Gets or sets the number of concurrent operations run client side during parallel query execution in the Azure Cosmos DB service. A positive property value limits the number of concurrent operations to the set value. If it is set to less than 0, the system automatically decides the number of concurrent operations to run.

public int MaxDegreeOfParallelism { get; set; }

Property Value

int

The maximum number of concurrent operations during parallel execution. Defaults to 0.

Examples

var queryable = client.CreateDocumentQuery<Book>(collectionLink, new FeedOptions { 
MaxDegreeOfParallelism = 5});

MaxItemCount

Gets or sets the maximum number of items to be returned in the enumeration operation in the Azure Cosmos DB service.

public int? MaxItemCount { get; set; }

Property Value

int?

The maximum number of items to be returned in the enumeration operation.

Examples

// Fetch query results 10 at a time.
using (var queryable = client.CreateDocumentQuery<Book>(collectionLink, new FeedOptions { MaxItemCount = 10 }))
{
    while (queryable.HasResults)
    {
        FeedResponse<Book> response = await queryable.ExecuteNext<Book>();
    }
}

Remarks

Used for query pagination. '-1' Used for dynamic page size.

PartitionKey

Gets or sets the PartitionKey for the current request in the Azure Cosmos DB service.

public PartitionKey PartitionKey { get; set; }

Property Value

PartitionKey

Examples

The following example shows how to read a document feed in a partitioned collection using PartitionKey. The example assumes the collection is created with a PartitionKeyDefinition on the 'country' property in all the documents.

await client.ReadDocumentFeedAsync(
    collection.SelfLink, 
    new RequestOptions { PartitionKey = new PartitionKey("USA") } );

Remarks

Partition key is required when read documents or attachments feed in a partitioned collection. Specifically Partition key is required for : ReadDocumentFeedAsync(string, FeedOptions, CancellationToken), ReadAttachmentFeedAsync(string, FeedOptions, CancellationToken) and ReadConflictFeedAsync(string, FeedOptions). Only documents in partitions containing the PartitionKey is returned in the result.

See Also

PartitionKeyRangeId

Gets or sets the partition key range id for the current request.

public string PartitionKeyRangeId { get; set; }

Property Value

string

Examples

The following example shows how to read a document feed in a partitioned collection from partition key range "20".

await client.ReadDocumentFeedAsync(
    collection.SelfLink, 
    new RequestOptions { PartitionKeyRangeId = "20" } );

Remarks

ReadFeed requests can use this to forward request to specific range. This is usefull in case of bulk export scenarios.

See Also

PopulateQueryMetrics

Gets or sets the PopulateQueryMetrics request option for document query requests in the Azure Cosmos DB service.

public bool PopulateQueryMetrics { get; set; }

Property Value

bool

Remarks

PopulateQueryMetrics is used to enable/disable getting metrics relating to query execution on document query requests.

RequestContinuation

Gets or sets the request continuation token in the Azure Cosmos DB service.

public string RequestContinuation { get; set; }

Property Value

string

The request continuation token.

Examples

// Resume query execution using the continuation from the previous query
var queryable = client.CreateDocumentQuery<Book>(collectionLink, new FeedOptions { RequestContinuation = prevQuery.ResponseContinuation });

ResponseContinuationTokenLimitInKb

Gets or sets the ResponseContinuationTokenLimitInKb request option for document query requests in the Azure Cosmos DB service.

public int? ResponseContinuationTokenLimitInKb { get; set; }

Property Value

int?

Remarks

ResponseContinuationTokenLimitInKb is used to limit the length of continuation token in the query response. Valid values are >= 0.

SessionToken

Gets or sets the session token for use with session consistency in the Azure Cosmos DB service.

public string SessionToken { get; set; }

Property Value

string

The session token for use with session consistency.

Examples

var queryable = client.CreateDocumentQuery<Book>(
    collectionLink, new FeedOptions { SessionToken = lastSessionToken });

Remarks

Useful for applications that are load balanced across multiple Microsoft.Azure.Documents.Client.DocumentClient instances. In this case, round-trip the token from end user to the application and then back to Azure Cosmos DB so that a session can be preserved across servers.