如何通过ASP.NET Core向Cosmos DB插入多个



有什么方法可以以最快的方式在带有ASP.NET核心的Cosmos Db中插入100万条记录吗?

最新的方法是在.NET SDK v3中使用批量支持。完整的教程在这里:

https://learn.microsoft.com/en-us/azure/cosmos-db/tutorial-sql-api-dotnet-bulk-import

您需要至少暂时增加数据库的吞吐量,以达到您所需的摄取速度。

Cosmos DB SDK允许通过Dotnet库的AllowBulkExecution选项使用批量executor进行批量插入

// Set retry options high during initialization (default values).
client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 30;
client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9;
IBulkExecutor bulkExecutor = new BulkExecutor(client, dataCollection);
await bulkExecutor.InitializeAsync();
// Set retries to 0 to pass complete control to bulk executor.
client.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 0;
client.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 0;

最新更新