Copy data from one CosmosDB database to another

I wanted to migrate the master data of my CosmosDB collections of the DEV environment to the UAT environment. I couldn't find any easy way to do it. I finally managed to do it and have listed the steps below. You will need to import it one collection at a time. Do feel free to let me know if there is a better way.

Step 1: Download the CosmosDB Data Migration tool

Download the precompiled library using this link. Unzip the downloaded file in your local file system and open the Dtui.exe which is the Graphical interface.

Step 2: Connection String for Source DB

We can get the connection string and keys from the Azure Portal Keys option under Settings. Copy the primary connection string into a notepad or text editor, we will need it in step 3.

Step 3: Source information tab

Select import from as Azure Cosmos DB. Update the source information with the connection string from step 2 and the collection name to be imported. screen1.png

Step 4: Connection String for Target DB

Create the Target CosmosDB database if it doesn't exist via the Azure Portal. You can use the Azure Documentation if you are not aware of how to do it. Follow step 2 for fetching the target's primary connection string

Step 5: Target Information tab

Select Export to as Azure Cosmos DB. Update all other information like source information with the connection string from step 4 and collection name which should be the same as the source along with your required partition key and ID for this collection. screen2.png

Step 6: Final step

Click Next and go through the tabs till the results tab where you will see the status of your import and export

Note: For serverless plan for CosmosDB, the collection is not auto-created in the target database, you will need to first create the collection in the Target DB before following the steps above.