Migrating data from Cosmos DB to local JSON files
Tags: azureapril, azure, database, tutorial
Published: 2019-04-17 16:00:53

---
title: Migrating data from Cosmos DB to local JSON files
published: true 
description: How to upload JSON data to Azure Cosmos DB
tags: azureapril, azure, database, tutorial
series: Azure April
cover_image: https://thepracticaldev.s3.amazonaws.com/i/pblyvmtj4y8bdqisyzey.jpeg
---

*We've selected our favorite tips and tricks created by [Michael Crump](https://twitter.com/mbcrump) and are delivering fresh technical content on Azure all April! Miss a day (or more)? [Catch up with the series](https://dev.to/t/azureapril).*

**Don't have Azure?** [Grab a free subscription](https://azure.microsoft.com/en-us/free?&WT.mc_id=azureapril_devto-blog-cxa). 

## 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](https://www.microsoft.com/en-us/download/confirmation.aspx?id=46436)

### 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**.

![](https://thepracticaldev.s3.amazonaws.com/i/d0u6f9pzvhah1ojlhsj7.png)

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**.

![](https://thepracticaldev.s3.amazonaws.com/i/160jrfmq1nnx4bgvils2.png)

In my case, I'll export to a local JSON file and select **Prettify JSON** and press **Next**.

![](https://thepracticaldev.s3.amazonaws.com/i/yb1d1xfmsh3y5sy3eqxl.png)

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. 

![](https://thepracticaldev.s3.amazonaws.com/i/khsv06uoxhr3jvfu9cyc.png)

![](https://thepracticaldev.s3.amazonaws.com/i/bvarhx11xgnwmysg0l1i.png)

You'll finally see the Import has completed with over 100K items transferred in a little under 2 minutes. 

![](https://thepracticaldev.s3.amazonaws.com/i/bvarhx11xgnwmysg0l1i.png)

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](https://docs.microsoft.com/en-us/azure/cosmos-db/introduction?WT.mc_id=azureapril_devto-blog-cxa)!

Also check out Monday's article from Jay Gordon: [Uploading your JSON data to Cosmos DB using the MongoDB API](https://dev.to/azure/uploading-your-json-data-to-azure-cosmos-db-for-mongodb-api-1mh9).

---

We'll be posting articles every day in April, so stay tuned or jump ahead and check out more tips and tricks [now](http://azuredev.tips).