Migrating data from old container to new partitioned container using change feed

☆樱花仙子☆ 提交于 2021-01-07 06:42:42

问题


1.Is using azure cosmosdb changefeed right approach, to migrate data from old containers to new partitioned containers?
2.Will azure cosmosdb changefeed have documents which are not at all modified even once till now?
3.If above are true, what are the steps involved in migrating data using azure cosmosdb change feed.


回答1:


You can certainly use Change Feed to achieve all this. Cosmos DB has several options to consume the Change Feed, one of them is using Azure Functions.

If you go with the Functions option, you can quickly do a simple migration mixing the Cosmos DB Trigger (with StartFromBeginning to true) and the Cosmos DB Output binding like so:

[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);
    }
}

There are some optimizations that can be applied for Multi master or geo-distributed applications (like using PreferredLocations if your Function is running on a different region).

Keep in mind that the Function acts as a live migration. It will start migrating documents that exist before it was deployed, and then it will continue to migrate new documents while it keeps running if your source collection keeps getting insert/updates.

If what you are needing is a cold migration, you could also use the Data Migration Tool



来源:https://stackoverflow.com/questions/56041986/migrating-data-from-old-container-to-new-partitioned-container-using-change-feed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!