Views returning invalid document ids that cause couchbase to hang trying to retrieve them

We use views a lot to query for data. In the past month our development server views started returning ids that do not exist in the actual database. Not all ids returned from a view do not exist, just some of them. Not only do they not exist, but they cause the server to hang trying to retrieve them. If I search in the couchbase console for an id that just never existed in the db I immediately get the error: “document does not exist”. If I search for one of these problem ids
returned by a view it just hangs for a while and eventually times out. We use the couchbase nodejs sdk to retrieve documents for our web portal, and if it does a getMulti with one of these ids it silently kills the connection. We can search for as many ids as we want after and we will not get any error, but every get will return a timeout until we
restart the connection.

In the couchbase logs I see this error when searching for one of the ids:

[ns_server:error,2016-04-20T19:54:53.749,ns_1@<0.19748.148>:menelaus_web:loop:170]Server error during processing: ["web request failed",
                                  "/pools/default/buckets/<bucket name>/docs/ffb9f1de-d0e1-4711-abb9-e46e5be5ad5e"},

Is anyone familiar with this error or know what is wrong with our views and how we can repair them?


Could you share your view function.

also your using Node.js SDK correct?

This is one of the views returning problem ids:

function (doc, meta) {
  if ("_sync")[0] != "" && !doc._deleted && doc._sync && doc._sync.channels
     && doc.type!="docType1" && doc.type!="docType2" && doc.type!='docType3'
     && doc.type!="docType4" && doc.type != "docType5" && doc.type != 'docType6'
     && doc.type != 'docType7' && doc.type != 'docType8' && doc.type != "docType9"
     && doc.type != 'docType10' && doc.type != 'docType11' && doc.type != 'docType12') {
    for (var channel in doc._sync.channels) {
      if (doc._sync.channels.hasOwnProperty(channel)) {

There is no reduce function. I’m emitting a value so that I can filter by it in my nodejs application. To connect in nodejs we use the following function. It’s run once when the application is started, and we pass the connection object to our express router objects that hold onto it for as long as the application is running.

function () {
    var cluster = new couchbase.Cluster('couchbase://');
    couchDb = cluster.openBucket(g.bucket, function(err) {
        if(err) {
            console.error("Failed to connect to bucket: " + err);

        console.log((new Date()).toISOString() + ' - Couchbase connected to bucket');

    return couchDb;

When running a query we use the following syntax (where couchDb is our couchbase connection object):

var query = ViewQuery.from('design_doc', 'viewName')

    couchDb.query(query, function(err,results) {
        if (err) {
            return callback(err);
        } else if (!results || (results && results.length == 0)) {
            return callback(null,[]);

        var numRows = results.length;
        var ids = [];
        for (var i=0; i < numRows;i++) {
            if (results[i] && (results[i].value == type)) {

        if (ids.length > 0) {

        couchDb.getMulti(ids, function (numDocsFailed, results) {
            var failedIds = [];
            if (numDocsFailed) {
                logger.error('getMulti failed for ' + numDocsFailed + ' docs');

            var retrievedDocs = [];
            for (var id in results) {
                if (results[id] && results[id].error) {
                } else {
                    var document = results[id].value;
                    if (document && document._sync) {
                        document._id = id;
                        document._rev = document._sync.rev;
                        delete document._sync;

    } else {

@alexegli , How many query per second or minute are you doing?
How many updates per second or minutes are you doing?
How many document do you have in couchbase?

Can you change from BEFORE to NONE?

During peak times about 1 query per minute, otherwise about 1 query every 5 or 10 minutes. Our couchbase console reports on average about 80 ops/second, but it peaks to about 110 at some points during the day. Not sure how many of those are updates but I think the majority are reads.We currently have 3259921 documents in the bucket with that view.
I know changing it from BEFORE to NONE will make it more responsive, but for this view we need to have the latest data so I can’t.

I was mistaken in which view was returning the problem ids. It is actually this view, which also has the built-in _count reduce function applied to it:

function (doc, meta) {
  if (doc.type == "docType" &&"_sync")[0] != "" && !doc._deleted && doc.userId && doc.startDateTime) {
    var start = new Date(doc.startDateTime);

We query it using this code:

var query = ViewQuery.from('design_doc', 'viewName')
    .range([members[i], startDate], [members[i], endDate], true)

couchDb.query(query, function (err, results) {

So we are actually using Update.NONE for this one.