Hi,
I'm new to CouchDB/nano and asynchronous JavaScript, and I hope this is
the right place to ask questions about how to use the nano API.
I'm trying to process all documents in a local CouchDB database with the
following code using nano (in the real program I want to get access to
all fields of each document):
const nano = require('nano')("http://localhost:5984");
const larch = nano.db.use('larch');
larch.list().then((allDocs) => {
var len = allDocs.rows.length;
console.log('total # of docs -> ' + len);
allDocs.rows.forEach((document) => {
larch.get(document.id).then((body) => {
console.log("id: " + body._id);
});
});
});
The output is:
total # of docs -> 80973
copydb.js:20
(node:24704) UnhandledPromiseRejectionWarning: Error: connect ENOBUFS
127.0.0.1:5984 - Local (undefined:undefined)
warning.js:18
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at internalConnect (net.js:960:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:284:19)
at GetAddrInfoReqWrap.emitLookup [as callback] (net.js:1106:9)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)
(node:24704) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 1)
warning.js:18
(node:24704) [DEP0018] DeprecationWarning: Unhandled promise rejections
are deprecated. In the future, promise rejections that are not handled
will terminate the Node.js process with a non-zero exit code.
warning.js:18
(node:24704) UnhandledPromiseRejectionWarning: Error: connect ENOBUFS
127.0.0.1:5984 - Local (undefined:undefined)
... and so on ...
This happens on a Windows 10 machine with CouchDB 2.1.1 and node
v8.11.2. When I restrict the processing to a few rows by taking a slice
of the allDocs.rows array then no errors occur.
I found some pointers on stackoverflow that this error may be caused by
too many HTTP requests being done in parallel. So it looks like I'm
using the API in a wrong way to process all documents in a database.
What would be the correct approach to avoid the "connect ENOBUFS" errors?
Thanks
Stephan