couchdb-iterator
A fast and easy to ease CouchDB iterator for views and all documents.
Installation
$ npm install couchdb-iterator
Usage
.couchdbIterator(couchdbAddr, [view], iterator, [options])
Calls iterator
for all rows of the database referenced by couchdbAddr
.
If a view
is supplied, iterates only over that view's rows.
This library aims to be fast, therefore iteration happens concurrently. The iterator function can be async but beware that order
is not guaranteed.
Examples:
const couchdbIterator = require('couchdb-iterator');
couchdbIterator('http://localhost:5984/my-db', 'my-designdoc/my-view', (row, index) => {
console.log(index, row.id, row.key, row.value);
})
.then((rowsCount) => {
console.log(`Iteration completed! ${rowsCount}`);
}, (err) => {
console.log('Iteration failed', err);
});
couchdbIterator('http://localhost:5984/my-db', 'my-designdoc/my-view', (row, index) => {
console.log(index, row.id, row.key, row.value);
})
.then((rowsCount) => {
console.log(`Iteration completed! ${rowsCount}`);
}, (err) => {
console.log('Iteration failed', err);
});
The couchdbAddr
argument must be connection string with protocol, host, port and database path (e.g.: http://localhost:5984/my-db) or a nano instance. The view
argument is a string in the form of designdoc/view
(e.g.: app/byUser).
Available options:
concurrency
: The concurrency in which the iterator
is called, defaults to 50
.nano
: Custom options to be used when creating the nano instance, defaults to null
.- The following querying options are available:
limit
, skip
, stale
, descending
, startkey
, startkey_docid
, endkey
, endkey_docid
, include_docs
and inclusive_end
(can be camelCased).
All querying options have no default value, except for limit
which is 500
. Also, stale
is automatically set to ok
after the first iteration to further improve performance.
Tests
$ npm test
$ npm test-cov
to get coverage report
License
Released under the MIT License.