Moving data from DocumentDB to Cloudant or CouchDB

Introducing the documentdbexport npm module

Glynn Bird
Mar 28, 2017 · 2 min read

In my last blog, we looked at . In this article we’re going to look at extracting data from Microsoft Azure’s DocumentDB service.

Image for post
Image for post
You’ll use the documentdbexport npm module to extract data, and the couchimport module to import it, of course.

Getting the data out

Once again, I’ve written a script to do this for you: .

First, install the tool:

$ npm install -g documentdbexport

Define a couple of environment variables with your Azure credentials:

$ export AZURE_ENDPOINT=""
$ export AZURE_KEY="GeIZysnonvgpk2"

Then, simply run documentdbexport, supplying the name of the database and collection to export:

$ documentdbexport --database iot --collection temperaturereadings
Export complete { records: 3, time: 0.145 }

The tool makes as many API calls as it needs to extract the data, converting the JSON to a more compact form as it goes.

Importing into CouchDB/Cloudant

We can use to do the import stage for us. Install it with:

$ npm install -g couchimport

Set an environment variable with your target Cloudant/CouchDB service’s URL:

$ export COUCH_URL=""

Then, run both the documentdbexport and couchimport commands together, piping the output of the former into the latter:

$ documentdbexport --database iot --collection temperaturereadings | couchimport --db iot --type jsonl

The --type jsonl parameter tells couchimport that it is to expect one JSON document per line and --db iot defines the name of the target database.

It’s that simple! You’ll find more details on command-line usage and programmatic access for . And please ♡ this article if you’d like to recommend it to other Medium readers.

Center for Open Source Data and AI Technologies

Things we made with data at IBM’s Center for Open Source…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store