Introducing Intra-Account Collection Copy in Azure Cosmos DB for MongoDB
Azure Cosmos DB, Microsoft’s globally distributed, multi-model database service, has always been at the forefront of empowering developers with innovative features and functionalities. In its pursuit of providing a seamless and efficient experience, Azure Cosmos DB recently announced the public preview of “Intra-Account Collection Copy” for Azure Cosmos DB for MongoDB. This feature allows users to effortlessly copy collections within the same account, offering enhanced data management and migration capabilities. In this blog post, we will delve into the significance of this update and explore how MongoDB support further complements this new capability.
Understanding Intra-Account Collection Copy
The new Intra-Account Collection Copy feature in Azure Cosmos DB for MongoDB enables users to copy collections within the same Azure Cosmos DB account in an offline manner. This functionality facilitates a wide range of use cases, including:
- Data Migration: Simplify the process of migrating data across collections or databases within the same Azure Cosmos DB account.
- Change shard key: If your data has evolved and queries are no longer efficient with the existing shard key, you can choose another shard key on a new collection and migrate the data using collection copy.
- Update Unique key index: Update unique key index of a container by defining new unique key index policy and migrating data to the new collection using collection copy.
- Move to dedicated/shared collection: Change the granularity at which throughput is provisioned by moving the collection from shared to dedicated throughput model and vice-versa using collection copy.
How Intra-Account Collection Copy Works?
To use the Intra-Account Collection Copy feature, follow these steps:
- Enable the Preview Feature: Register for preview feature Intra-account offline collection copy (MongoDB)
- Install Azure Cosmos DB preview extension: Ensure that you have the Azure Cosmos DB preview extension installed on Azure CLI.
- Select the Source and Destination Collections: Choose the source collection and the destination collection where you want to copy the data.
- Start the Copy Operation: Initiate the collection copy operation from the Azure CLI.
- Monitor the Progress: Keep track of the copy progress and check for completion.
Set shell variables
First, set all of the variables that each individual script uses.
$resourceGroup = "<resource-group-name>" $accountName = "<cosmos-account-name>" $jobName = "" # This should be unique for each job within an account. $sourceDatabase = "" $sourceCollection = "" $destinationDatabase = "" $destinationCollection = ""
Create intra-account collection copy job for API for MongoDB account
az cosmosdb dts copy ` --resource-group $resourceGroup ` --account-name $accountName ` --job-name $jobName ` --source-mongo database=$sourceDatabase collection=$sourceCollection ` --dest-mongo database=$destinationDatabase collection=$destinationCollection
Monitor the progress of a collection copy job
View the progress and status of a copy job:
az cosmosdb dts show ` --resource-group $resourceGroup ` --account-name $accountName ` --job-name $jobName
This is just a short example of how to get started, you can check out the detailed steps to perform collection copy in how to do collection copy documentation.
Introducing the Intra-Account Collection Copy feature in Azure Cosmos DB for MongoDB is a significant step towards enhancing data management and migration capabilities. It empowers developers to copy collections within the same account efficiently, enabling seamless data migration, backups, and more. Get started by heading over to the Intra-Account Collection Copy documentation here.
About Azure Cosmos DB
Azure Cosmos DB is a fully managed and serverless distributed database for modern app development, with SLA-backed speed and availability, automatic and instant scalability, and support for open-source PostgreSQL, MongoDB, and Apache Cassandra. Try Azure Cosmos DB for free here. To stay in the loop on Azure Cosmos DB updates, follow us on Twitter, YouTube, and LinkedIn.