文档DB:大容量导入存储过程:在 COSMOS DB 中插入多个分区键文档



我正在使用document client在 Cosmos 数据库中批量插入存储过程,但我面临的挑战是,我需要批量插入可能具有不同partition keys的文档。

有什么办法可以实现吗?

我目前正在使用以下代码:

Uri uri = UriFactory.CreateStoredProcedureUri("test-db", "test-collection", "sp_bulk_insert");
RequestOptions options = new RequestOptions { PartitionKey = new PartitionKey("patient")};
var result = await _client.ExecuteStoredProcedureAsync<string>(uri, options , patientInfo, pageInfo);
return result;

但是我也有pageInfo具有分区键的对象:"页面",但给定RequestOptions中的PartitionKey是"耐心",这是patientInfo对象的分区键

当我尝试执行SP时,它给出以下错误:

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

存储过程的作用域为单个分区键,因此这是不可能的。此外,也没有理由将存储过程用于批量操作。最好使用 .NET SDK v3 并利用其中的批量支持。https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/BulkSupport

谢谢。

最新更新