Search code examples
node.jscouchbasecouchbase-litecouchnode

Bulk operation has failed in Couchbase


I'm new in Couchbase. I'm trying to some basic operations with Node.js from the Couchbase Documents on Couchbase Server 3.0.1 . When I try the bulk operations, the codes - that have gotten from Couchbase docs - has failed.

There is a Data Bucket named "test". And the bucket has 2 records they have doc number 1 and 2. I can success if I get the documents one by one.

But the following codes return an error such as;

throw new TypeError('First argument needs to be a string or buffer.');

My codes;

var couchbase = require("couchbase");
var cluster = new couchbase.Cluster('192.168.170.129:8091');
var bucket = cluster.openBucket('test');

// Bulk operation

bucket.get(['1', '2'], function(err, res) {

  if(err) {
    console.log("one or more operation failed", err);
    return;
  }

  console.log("success!", res);

});

Edited: I'm using Couchbase Node.js 2.0


Solution

  • From the Couchbase Node.js 2.0.0 API documentation the get() only operates on a single key.

    The function you are looking for is getMulti():

    bucket.getmulti(['1', '2'], function(err, res) {
    
      if(err) {
        console.log("one or more operation failed", err);
        return;
      }
    
      console.log("success!", res);
    
    });