你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

partition_key Module

Create partition keys in the Azure Cosmos DB SQL API service.

Classes

NonePartitionKeyValue

Represents partition key missing from the document.

NullPartitionKeyValue

Represents null value for a partition key.

PartitionKey

Key used to partition a container into logical partitions.

See https://free.blessedness.top/azure/cosmos-db/partitioning-overview#choose-partitionkey for information on how to choose partition keys.

This constructor supports multiple overloads:

  1. Single Partition Key:

    Parameters:

    • path (str): The path of the partition key.

    • kind (Literal["Hash"], optional): The kind of partition key. Defaults to "Hash".

    • version (int, optional): The version of the partition key. Defaults to 2.

    Example:

    
    >>> pk = PartitionKey(path="/id")
    
  2. Hierarchical Partition Key:

    Parameters:

    • path (list[str]): A list of paths representing the partition key, supports up to three hierarchical levels.

    • kind (Literal["MultiHash"], optional): The kind of partition key. Defaults to "MultiHash".

    • version (int, optional): The version of the partition key. Defaults to 2.

    Example:

    
    >>> pk = PartitionKey(path=["/id", "/category"], kind="MultiHash")