couchcmd
CouchDB command line client for Node.js
introduction
couchcmd is a command line utility for couchdb using cradle
synopsis
couchcmd [host [port]]
CouchDB> use sample
CouchDB> all
CouchDB> get key
CouchDB> save key {a : 'b'}
CouchDB> merge key {a : 'b'}
CouchDB> remove key
installation
$ npm install couchcmd
Commands
Couchcmd exposes Cradle's API through commands.
Opening a connection
CouchDB> connect [host [port]]
Defaults to 127.0.0.1:5984
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 databasesconfig
: Get server configinfo
: Get server informationstats
: Statistics overviewactiveTasks
: Get list of currently active tasks
database level
dbinfo
: Database informationall
: Get all documentsallBySeq
: Get all documents by sequencecompact
: Compact databaseviewCleanup
: Cleanup old view data