TIP
💡 Learn more : Azure Cosmos DB (opens new window).
# Migrating Data from Cosmos DB to Local JSON files
# Using the Data Migration Tool with Cosmos DB
One tasks that seems to come up over and over is migrating data from one database/format into another. I recently used Cosmos DB as my database to store every tweet that came out of Ignite. Once I had the data and wouldn't be using Cosmos DB any more for that exercise, I needed to dump the data out to a local file to preserve the data and save money. Here is how I did it.
# The Tools
Download and install the Azure DocumentDB Data Migration Tool (opens new window)
# Get to Work
Ensure you have a Cosmos DB database and collection created that you wish to migrate out.
Go to Keys (inside your Cosmos DB blade in the portal) to copy the Primary Connection String
You'll need to append the Database name to the end of the string. For example Database=cosmosdb-ignite
will be appended to the Key copied earlier AccountEndpoint=https://mbcrump.documents.azure.com:443/;AccountKey=VxDEcJblah==;Database=cosmosdb-ignite
. Save this for later.
Open the Data Migration Tool and under Source Information, select DocumentDB as shown below.
You'll need to add the ConnectionString (that we just created) along with the Collection and in my case it is items
. We'll take the defaults on the rest and press Verify and if successful, then press Next.
In my case, I'll export to a local JSON file and select Prettify JSON and press Next.
On the next screen, you'll see a View Command to see the command that will be used to migrate your data. This is helpful to just learn the syntax.
You'll finally see the Import has completed with over 100K items transferred in a little under 2 minutes.
We now have our local JSON file and can use it however we want! Awesome!