【问题标题】:DocumentDB: Bulk-Import Stored Procedure: Insert multiple partition key documents in COSMOS DBDocumentDB:批量导入存储过程:在 COSMOS DB 中插入多个分区键文档
【发布时间】:2020-01-24 07:47:23
【问题描述】:

我正在使用 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 具有分区键的对象:“page”,但在 RequestOptions 中给出的 PartitionKey 是“耐心”,即 patientInfo 对象的分区键

当我尝试执行 SP 时出现以下错误:

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

【问题讨论】:

  • 您是否使用批量执行程序库,因为它可以进行分区拆分?

标签: azure azure-cosmosdb azure-cosmosdb-sqlapi


【解决方案1】:

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

谢谢。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多