通过文档ID检索时是否需要分区键 [英] Is the partition key required when retrieving by the document ID

查看:64
本文介绍了通过文档ID检索时是否需要分区键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不指定分区键的情况下通过其ID检索文档?

Is it possible to retrieve a document by its ID without specifying the partition key?

通过阅读文档,我的理解是:如果未指定分区键,则查询将在所有分区之间散开:

My understanding from reading the documentation is that the query will fan out across all partitions when the partition key is not specified:

以下查询在分区键上没有过滤器 (DeviceId),并扇出到执行它的所有分区 针对分区的索引.请注意,您必须指定 EnableCrossPartitionQuery(x-ms-documentdb-query-enablecrosspartition 在REST API中),以使SDK可以跨分区执行查询.

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是经过特殊处理的,所以我希望不需要为此启用跨分区查询.

This makes sense with non-key properties, but given the ID is treated specially, I'm hoping I won't need to enable cross partition queries for it.

如果我确实需要启用跨分区查询,这会是一项昂贵的操作吗?

If I do need to enable cross partition queries, would this be an expensive operation?

推荐答案

仅通过ID进行查询将是跨分区操作.您应该在FeedOptions.PartitionKey的这些查询中包括分区键,或者将其作为过滤器的一部分. 在DocumentDB中,ID在集合中的所有文档中不是唯一.相反,分区键"和"id"的组合是主键,可以唯一地标识集合中的文档.

Query by just ID will be a cross partition operation. You should include the partition key in these queries in FeedOptions.PartitionKey, or as part of the filter. In DocumentDB, ID is not unique across all documents within a collection. Instead, the combination of "partition key" and "id" is the primary key and uniquely identifies documents within a collection.

某些应用程序将分区键编码为ID的一部分,例如分区键将是客户ID,并且ID = "customer_id.order_id",因此您可以从ID值中提取分区键.

Some applications encode partition key as part of the ID, e.g. partition key would be customer ID, and ID = "customer_id.order_id", so you can extract the partition key from the ID value.

这篇关于通过文档ID检索时是否需要分区键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆