如何通过 ASP.NET 核心向 Cosmos DB 插入多个?

How to insert many to Cosmos DB by ASP.NET Core?

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

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;

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

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

您至少需要暂时增加数据库的吞吐量,以实现您想要的摄取速度。