span
span

Reputation: 5624

Does setting FeedOptions.EnableCrossPartitionQuery to false need to be combined with FeedOptions.PartitionKey?

I want to send a document query using:

var query = documentClient.CreateDocumentQuery<ArticleEntity>(collectionLink, feedOptions)
    .Where(entity => entity.Type == someType)
    .AsDocumentQuery();

In the FeedOptions it is possible to set EnableCrossPartitionQuery to false to only query a single partition.

From the docs it says:

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.

So I am not sure how to interpret "query is not scoped to single partition key value".

Do I need to also set the partition key to make sure the "query is scoped" properly or will the SDK automatically determine the partition key from my entity?

Upvotes: 2

Views: 1018

Answers (1)

Kirk Larkin
Kirk Larkin

Reputation: 93053

Yes, you also need to specify the partition key explicitly, using FeedOptions and its PartitionKey property as you've noted. Here's an example:

feedOptions.PartitionKey = new PartitionKey("yourPartitionKey");

var query = documentClient.CreateDocumentQuery<ArticleEntity>(collectionLink, feedOptions)
    .Where(entity => entity.Type == someType)
    .AsDocumentQuery();

It is setting the PartitionKey property that scopes the query to a single partition.

Upvotes: 1

Related Questions