I'm trying to execute a stored procedure on a partitioned collection (server side partitioning) from the .net SDK (v1.6.3).
await client.ExecuteStoredProcedureAsync<string>(UriFactory.CreateStoredProcedureUri("db0", "collection0", "testsproc0"), storedProcedureParams);
I receive the error "PartitionKey value must be supplied for this operation". In fact, I see this error in the Azure Portal when I play around with the Script Explorer. However, I see no way to add a PartitionKey. Is this a limitation with the API and partitioned collections right now, or am I missing something?
Use item ID as the partition key One possible example of such a property is the item ID. For small read-heavy containers or write-heavy containers of any size, the item ID is naturally a great choice for the partition key. The system property item ID exists in every item in your container.
A partition key consists of a path, like "/firstname", or "/name/first". You can use alphanumeric and underscore characters in the path. The partition key needs to be a JSON property in the documents that you store in the container.
It isn't mandatory to explicitly tell cosmos about the partition key (via argument or CosmosItemRequestOptions) during a CRUD operation. If unavailable, cosmos reads the document (which is being added/updated) and finds the partition key.
you can pass in the partition key by using the overloaded ExecuteStoredProcedureAsync method with RequestOptions. For example,
await client.ExecuteStoredProcedureAsync<DeviceSignal>(
UriFactory.CreateStoredProcedureUri("db", "coll", "SetLatestStateAcrossReadings"),
new RequestOptions { PartitionKey = new PartitionKey("XMS-001") }, sprocsParams);
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