Question

I'm creating a view to obtain specifics values in my couchdb database, works fine in a little database, but when I have more than 1.5 Millions of records, an exception appears with: Socket hang up. I read other references like CouchDb unhandled 'error' event - Node js , but looks like if the error with the view. In the couchdb documentation never says about the max numbers of records in a view. Someone know what I can do to solve it. If I execute the view as temporaylly, the follow message appears: An error occurred querying the database (Only in the view with 1.5 millions of records).

Im using the follow codes to connect couchdb with node.js, for some reason, the code works with few records.

dbCouchdb.view("Where", "processId" , {key: "e2450051-b119-0ca7-d0be-fbae7887fea5", limit: 1}, function(err, body) {
      console.log(err);
    });

And the error:

{ [Error: error happened in your connection]
  name: 'Error',
  scope: 'socket',
  errid: 'request',
  code: 'ECONNRESET',
  description: 'socket hang up',
  stacktrace:
   [ 'Error: socket hang up',
     '    at createHangUpError (http.js:1472:15)',
     '    at Socket.socketOnEnd [as onend] (http.js:1568:23)',
     '    at Socket.g (events.js:180:16)',
     '    at Socket.EventEmitter.emit (events.js:117:20)',
     '    at _stream_readable.js:920:16',
     '    at process._tickCallback (node.js:415:13)' ] }
Was it helpful?

Solution

The problem is that the view is not indexed when you add documents to it. It uses lazy initialization, so when you access the 1.5M view, it could take for a long tim for the first time.

The nodejs is waiting for some time while view index is build, but it takes longer than expected. You can try to open view's URL in browser to see how long does it take for the first time and for the second one.

So in your situation is is important to optimize the view's map and reduce function for performance.

It is a known issue, but just in case: if you have 1.5M docs, you can forget about reduce functions. Only build-in ones will work fast enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top