Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the partition key required when retrieving by the document 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:

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?

like image 354
Sam Avatar asked Jan 14 '17 09:01

Sam


1 Answers

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.

like image 179
Aravind Krishna R. Avatar answered Oct 16 '22 14:10

Aravind Krishna R.