DEV Community 👩‍💻👨‍💻

Cover image for Migrating data from Cosmos DB to local JSON files
Burke Holland for Microsoft Azure

Posted on

Migrating data from Cosmos DB to local JSON files

We've selected our favorite tips and tricks created by Michael Crump and are delivering fresh technical content on Azure all April! Miss a day (or more)? Catch up with the series.

Don't have Azure? Grab a free subscription.

Using the Data Migration Tool with Cosmos DB

One task 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

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 8Primary 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=;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!

Want more Cosmos DB? Check out our quickstarts and tutorials!

Also check out Monday's article from Jay Gordon: Uploading your JSON data to Cosmos DB using the MongoDB API.

We'll be posting articles every day in April, so stay tuned or jump ahead and check out more tips and tricks now.

Top comments (1)

thaianhduc profile image
Thai Anh Duc

I used the tool to import from a large JSON file into CosmosDB locally for my development environment. I worked perfectly.

Timeless DEV post...

How to write a kickass README

Arguably the single most important piece of documentation for any open source project is the README. A good README not only informs people what the project does and who it is for but also how they use and contribute to it.

If you write a README without sufficient explanation of what your project does or how people can use it then it pretty much defeats the purpose of being open source as other developers are less likely to engage with or contribute towards it.