Sergei Basharov
Sergei Basharov

Reputation: 53850

Examples and documentation for couchnode

I am trying to integrate couchbase into my NodeJS application with couchnode module. Looks like it lacks of documentation. I see a lot of methods with parameters there in the source code but I can't find much information about how they work. Could you please share me with some, may be examples of code? Or should I read about these methods from other languages' documentation as there are chances they are the same?

Upvotes: 1

Views: 934

Answers (2)

Rick Rutt
Rick Rutt

Reputation: 86

I adapted an AngularJS and Node.js web application that another developer wrote for querying and editing Microsoft Azure DocumentDB documents to let it work with Couchbase:

https://github.com/rrutt/cb-bread

Here is the specific Node.js module that performs all the calls to the Couchbase Node SDK version 2.0.x:

https://github.com/rrutt/cb-bread/blob/dev/api/lib/couchbaseWrapper.js

Hopefully this provides some help in understanding how to configure arguments for many of the Couchbase API methods.

Upvotes: 0

Patrick
Patrick

Reputation: 8063

To make development easier, I wrote a little helper (lib/couchbase.js):

var cb = require('couchbase'),
    config;

if(process.env.NODE_ENV === 'production') {
    config = require('../lib/config');
} else {
    config = require('../lib/localconfig');
}

module.exports = function(bucket, callback) {
  config.couchbase.bucket = bucket;
  cb.connect(config.couchbase, callback);
};

Here's some example code for a view and async/each get operation. Instead of 'default' you can use different buckets.

var couchbase = require('../lib/couchbase');
couchbase('default', function(error, cb) {
    cb.view('doc', 'view', {
        stale: false
    }, function(error, docs) {
        async.each(docs, function(doc, fn) {
            cb.get(doc.id, function(error, info) {
                // do something
                fn();
            }
        }, function(errors) {
            // do something
        });
    });
});

Upvotes: 1

Related Questions