Is the partition key required when retrieving by the document ID

本小妞迷上赌 提交于 2019-12-06 02:58:02

问题


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:

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.

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/41648364/is-the-partition-key-required-when-retrieving-by-the-document-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!