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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With