node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



CouchDB command line client for Node.js


couchcmd is a command line utility for couchdb using cradle


couchcmd [host [port]]

CouchDB> use sample
CouchDB> all
CouchDB> get key
CouchDB> save key {a : 'b'}
CouchDB> merge key {a : 'b'}
CouchDB> remove key


$ npm install couchcmd


Couchcmd exposes Cradle's API through commands.

Opening a connection

CouchDB> connect [host [port]]

Defaults to

creating a database

CouchDB> create dbname or use dbname

You can check if a database exists with the exists command.

CouchDB> exists dbname

fetching a document (GET)

CouchDB> get vader

If you want to get a specific revision for that document, you can pass it as the 2nd argument to get.

Querying a view

CouchDB> view characters/all

creating/updating documents

In general, document creation is done with the save command, while updating is done with merge.

creating with an id (PUT)

CouchDB> save vader {name: 'darth', force: 'dark'}

creating without an id (POST)

CouchDB> save {force: 'dark', name: 'Darth'}

updating an existing document with the revision

CouchDB> save luke 1-94B6F82 {force: 'dark', name: 'Luke'}

Note that when saving a document this way, CouchDB overwrites the existing document with the new one. If you want to update only certain fields of the document, you have to fetch it first (with get), make your changes, then resave the modified document with the above command.

If you only want to update one or more attributes, and leave the others untouched, you can use the merge command:

CouchDB> merge luke  {jedi: true}

bulk insertion

If you want to insert more than one document at a time, for performance reasons, you can pass an array to save:

CouchDB> save [ {name: 'Yoda'}, {name: 'Han Solo'}, {name: 'Leia'} ]

removing documents (DELETE)

To remove a document, use remove method, passing the latest document revision.

CouchDB> remove luke  1-94B6F82

If remove is called without a revision, and the document was recently fetched from the database, it will attempt to use the cached document's revision.

Changes API

For a one-time _changes query, simply use changes :

CouchDB> changes

Or if you want to see changes since a specific sequence number:

CouchDB> changes  {since: 42}

and to include the affected documents

CouchDB> changes  {since: 42, include_docs: true}

Other Commands

CouchDB Server level

  • databases: Get list of databases
  • config: Get server config
  • info: Get server information
  • stats: Statistics overview
  • activeTasks: Get list of currently active tasks

database level

  • dbinfo: Database information
  • all: Get all documents
  • allBySeq: Get all documents by sequence
  • compact: Compact database
  • viewCleanup: Cleanup old view data