azure-cosmosdb - 使用更改源将数据从旧容器迁移到新的分区容器
问题描述
1.是否使用azure cosmosdb changefeed正确的方法,将数据从旧容器迁移到新的分区容器?
2. azure cosmosdb changefeed 会有文件到现在都没有修改过吗?
3.如果上述情况属实,使用 azure cosmosdb change feed 迁移数据的步骤是什么。
解决方案
您当然可以使用 Change Feed 来实现这一切。Cosmos DB 有多个使用更改源的选项,其中之一是使用 Azure Functions。
如果您使用 Functions 选项,则可以快速执行简单的迁移,混合Cosmos DB 触发器(使用StartFromBeginning
to true
)和Cosmos DB 输出绑定,如下所示:
[FunctionName("Migration")]
public static async Task Run(
[CosmosDBTrigger(
databaseName: "your-source-database",
collectionName: "your-source-collection",
ConnectionStringSetting = "Connection-String-Setting-Name-For-Source-Account",
StartFromBeginning = true,
CreateLeaseCollectionIfNotExists = true,
)] IReadOnlyList<Document> source,
[CosmosDB(
databaseName: "your-destination-database",
collectionName: "your-destination-collection",
ConnectionStringSetting = "Connection-String-Setting-Name-For-Destination-Account" // In case your destination is on a different account, otherwise, it could be the same value as the Trigger
)] IAsyncCollector<Document> destination,
ILogger log)
{
foreach(var doc in source){
await destination.AddAsync(doc);
}
}
有一些优化可以应用于多主或地理分布式应用程序(例如,PreferredLocations
如果您的函数在不同区域运行时使用)。
请记住,函数充当实时迁移。它将开始迁移在部署之前存在的文档,然后如果您的源集合不断获得插入/更新,它将在继续运行的同时继续迁移新文档。
如果您需要的是冷迁移,您还可以使用数据迁移工具
推荐阅读
- android - 如何在 Fragment 中使用 Compose?
- php - Codeigniter,字段未更新,但其他字段将更新
- dynamics-crm - 如何获取任何 crm 实体属性的 edm 数据类型(odata 类型)
- performance - 使用 firebase 实时数据库了解 ionic 4 应用程序的性能问题
- pandas - 根据熊猫中多个列值的条件对行进行分组
- java - 从未格式化的 url 下载图像
- python - 关于 CSV 文件的基本 python 问题
- visual-studio - 如何在 Visual Studio 中使用键盘“向后导航”和“向前导航”?
- python - @jupyterlab/vega6-extension 在哪里?
- visual-c++ - goanywhere 服务器的 ftpputfile