Export and Import a CouchDB database

Simone Di Cicco
The Reverse Angle

--

If you are looking at this article you probably know what CouchDB is, but a little foreword won’t hurt anyone.

Apache CouchDB is an open-source document-oriented NoSQL database. It is using JSON as a data storage format, JavaScript as its query/data manipulation language and leveraging HTTP to expose a REST API interface to interact directly with it.

Cool, this REST API interface is exactly what we need for our purpose, which is moving data back and forth between different hosts and/or databases.

API to use

This is gonna be pretty much easy because we need just two APIs:

  • Retrieve all the documents (docs);
  • Bulk document insert (docs).

What we have to do

This task is straightforward as well. We have a bunch of operation to do and all in series:

Figure 1

The program

This little program is coded in JavaScript and runs directly with Node, there isn’t the need for any further dependency, so it’s cool, you just need Node. I mean… not because packages suck. I am actually in love with NPM but I thought it would have been better to have something ready-to-go for this tutorial.

https://gist.github.com/ukaoskid/e790e4c4e70949e01411cca3d23f9e1c

If you think you can make it better or have any suggestions, just comment here or on my Gist.

Made with love, enjoy!

--

--

Simone Di Cicco
The Reverse Angle

Solutions Architect @Accedo • CTO @Beam • AWS SAP • PMI CAPM© • Cybersecurity freak • Galileo Galilei lover