Partition – whether the partition key is required when retrieved by the document ID

Can a document be retrieved by its ID without specifying a partition key?

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

< p>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< br> EnableCrossPartitionQuery (x-ms-documentdb-query-enablecrosspartition
in the REST API) to have the SDK to execute a query across partitions
.

The key attribute is meaningful, but since the ID is handled specifically, I hope I don’t need to enable cross-partition query for it.

If I do need to enable cross-partition query, it will be an expensive operation NS?

querying only by ID will be a cross-partition operation. You should include these in FeedOptions.PartitionKey The query includes the partition key, or as part of the filter.
In DocumentDB, the ID is not unique among all documents in the collection. On the contrary, the combination of “partition key” and “id” is the primary key and is unique Identify the documents in the collection.

Some applications encode the partition key as part of the ID. For example, the partition key is the customer ID, ID = “customer_id.order_id”, so you can get the ID Extract the partition key from the value.

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

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

< p>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< br> EnableCrossPartitionQuery (x-ms-documentdb-query-enablecrosspartition
in the REST API) to have the SDK to execute a query across partitions
.

The key attribute is meaningful, but since the ID is handled specifically, I hope I don’t need to enable cross-partition query for it.

If I do need to enable cross-partition query, it will be an expensive operation NS?

Querying by ID alone 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 among all documents in the collection. On the contrary, the combination of “partition key” and “id” is the primary key and uniquely identifies the document in the collection.

Some applications encode the partition key as part of the ID. For example, the partition key is the customer ID, ID = “customer_id.order_id”, so you can extract the partition key from the ID value.

p>

Leave a Comment

Your email address will not be published.