1
votes

Why partition key has to be mentioned when making point queries against partitioned collection using sql api SDK?

Is there way to execute point queries against partitioned collection using sql api SDK without mentioning "PartitionKey"? as it is point query.

Working Example:
// - db_id is the ID property of the Database
// - coll_id is the ID property of the DocumentCollection
// - doc_id is the ID property of the Document wish to read.
var docUri = UriFactory.CreateDocumentUri("db_id", "coll_id", "doc_id");
await docClient.ReadDocumentAsync(docUri, new RequestOptions { PartitionKey = new PartitionKey(actualId) });

Non working example: var docUri = UriFactory.CreateDocumentUri("db_id", "coll_id", "doc_id");
await docClient.ReadDocumentAsync(docUri);

Below query without partition key, fails with errormessage: "PartitionKey value must be supplied for this operation."

Why partition key needs to be mentioned for point query against partitioned collection?

1

1 Answers

0
votes

PartitionKey is mandatory, When you create an account you will be asked to provide the Partition Key. It is used for sharding and it acts as a logical partition for your data, provides Cosmos DB with a natural boundary for distributing data across partitions. So it comes with the design.

So whenever you are querying data from cosmosdb with SDK it is necessary to pass the PartitionKey

The reason ParitionKey is needed because that CosmosDB does not parse the query until it locates the data.