按文档ID检索时是否需要partition key
Is the partition key required when retrieving by the document ID
是否可以在不指定分区键的情况下通过文档 ID 检索文档?
我阅读 documentation 的理解是,当未指定分区键时,查询将跨所有分区展开:
The following query does not have a filter on the partition key
(DeviceId) and is fanned out to all partitions where it is executed
against the partition's index. Note that you have to specify the
EnableCrossPartitionQuery (x-ms-documentdb-query-enablecrosspartition
in the REST API) to have the SDK to execute a query across partitions.
这对非键属性有意义,但考虑到 ID 被特殊处理,我希望我不需要为它启用跨分区查询。
如果我确实需要启用跨分区查询,这会是一项昂贵的操作吗?
仅按ID查询将是跨分区操作。您应该将分区键包含在 FeedOptions.PartitionKey
中的这些查询中,或作为过滤器的一部分。
在 DocumentDB 中,ID 在一个集合中的所有文档中是 而不是 唯一的。相反,"partition key" 和 "id" 的组合是主键并唯一标识集合中的文档。
一些应用程序将分区键编码为 ID 的一部分,例如分区键将是客户 ID,ID = "customer_id.order_id"
,因此您可以从 ID 值中提取分区键。
是否可以在不指定分区键的情况下通过文档 ID 检索文档?
我阅读 documentation 的理解是,当未指定分区键时,查询将跨所有分区展开:
The following query does not have a filter on the partition key (DeviceId) and is fanned out to all partitions where it is executed against the partition's index. Note that you have to specify the EnableCrossPartitionQuery (x-ms-documentdb-query-enablecrosspartition in the REST API) to have the SDK to execute a query across partitions.
这对非键属性有意义,但考虑到 ID 被特殊处理,我希望我不需要为它启用跨分区查询。
如果我确实需要启用跨分区查询,这会是一项昂贵的操作吗?
仅按ID查询将是跨分区操作。您应该将分区键包含在 FeedOptions.PartitionKey
中的这些查询中,或作为过滤器的一部分。
在 DocumentDB 中,ID 在一个集合中的所有文档中是 而不是 唯一的。相反,"partition key" 和 "id" 的组合是主键并唯一标识集合中的文档。
一些应用程序将分区键编码为 ID 的一部分,例如分区键将是客户 ID,ID = "customer_id.order_id"
,因此您可以从 ID 值中提取分区键。