Udostępnij za pośrednictwem


RequestOptions.PartitionKey Property

Definition

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

public Microsoft.Azure.Documents.PartitionKey PartitionKey { get; set; }
member this.PartitionKey : Microsoft.Azure.Documents.PartitionKey with get, set
Public Property PartitionKey As PartitionKey

Property Value

Examples

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

await client.ReadDocumentAsync(
    document.SelfLink,
    new RequestOptions { PartitionKey = new PartitionKey(document.Id) } );

Remarks

Partition key is used to identify the target partition for this request. It must be set on read and delete operations for all document requests; create, read, update and delete operations for all document attachment requests; and execute operation on stored producedures.

For create and update operations on documents, the partition key is optional. When absent, the client library will extract the partition key from the document before sending the request to the server.

Applies to

See also