Azure DocumentDB - Requests originating from scripts cannot reference partition keys other than the one for which client request was submitted

前端 未结 1 1535
攒了一身酷
攒了一身酷 2021-01-19 06:32

Using the c# .Net client SDK, I am calling the ExecuteStoredProcedureAsync method as follows:

sproc_response = await client.ExecuteStoredProcedureAsync

        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 07:02

    When you create a partitioned collection in Cosmos you are required to pick a partition key which is a path in the JSON representation of your documents that will be used to place the document in the correct partition. If you're attempting to insert a document with no partition key it's going to get grouped in a special partition for documents with no partition key. You're specifying that the stored procedure should run within the context of a given partition but then trying to use it to insert a document into a different partition (the undefined one). Make sure that your POCO has a property on it that maps to the value you chose for the partition key on your collection.

    You clearly know what partition you'd like to place the document in, as you're passing a value in RequestOptions for PartitionKey. Now ensure that your POCO includes this value on a property that matches the partition key you chose when you created your collection. The document will still have an auto generated Id if you do not provide one. Alternatively, you can just add the partition key to your document inside the Sproc as you're dealing with a dynamic JS object.

    doc.partitionKey = my_partition_key
    

    0 讨论(0)
提交回复
热议问题