lib/connect-couchbase.js
function CouchbaseStore(options) {
        var self = this;

        options = options || {};
        Store.call(this, options);
        this.prefix = null == options.prefix
            ? 'sess:'
            : options.prefix;

        var connectOptions = {};
        if (options.hasOwnProperty("host")) {
            connectOptions.host = options.host;
        } else if (options.hasOwnProperty("hosts")) {
            connectOptions.host = options.hosts;
        }

        if (options.hasOwnProperty("username")) {
            connectOptions.username = options.username;
        }

        if (options.hasOwnProperty("password")) {
            connectOptions.password = options.password;
        }

        if (options.hasOwnProperty("bucket")) {
            connectOptions.bucket = options.bucket;
        }

        if (options.hasOwnProperty("cachefile")) {
            connectOptions.cachefile = options.cachefile;
        }

        if (options.hasOwnProperty("connectionTimeout")) {
            connectOptions.connectionTimeout = options.connectionTimeout;
        }

        if (options.hasOwnProperty("operationTimeout")) {
            connectOptions.operationTimeout = options.operationTimeout;
        }


        if (options.hasOwnProperty("db")) {
            connectOptions.db = options.db; // DB Instance
        }

        if ( typeof(connectOptions.db) != 'undefined' ) {
            this.client = connectOptions.db;
        } else {
            var Couchbase = require('couchbase');
            var cluster = new Couchbase.Cluster(connectOptions.host);

            var bucket = connectOptions.bucket;
            var prefix = this.prefix;

            this.queryAll = Couchbase.N1qlQuery.fromString('SELECT `'
                + bucket + '`.* FROM `'
                + bucket + '` WHERE SUBSTR(META(`'
                + bucket + '`).id, 0, '
                + prefix.length + ') = "'
                + prefix + '"');

            this.client = cluster.openBucket(connectOptions.bucket, connectOptions.password, function(err) {
                if (err) {
                    console.log("Could not connect to couchbase with bucket: " + connectOptions.bucket);
                    self.emit('disconnect', err);
                } else {
                    self.emit('connect');
                }
            });
        }

        this.client.connectionTimeout = connectOptions.connectionTimeout || 10000;
        this.client.operationTimeout = connectOptions.operationTimeout || 10000;

        this.ttl = options.ttl || null;
    }
function CouchbaseStore(options) {
        var self = this;

        options = options || {};
        Store.call(this, options);
        this.prefix = null == options.prefix
            ? 'sess:'
            : options.prefix;

        var connectOptions = {};
        if (options.hasOwnProperty("host")) {
            connectOptions.host = options.host;
        } else if (options.hasOwnProperty("hosts")) {
            connectOptions.host = options.hosts;
        }

        if (options.hasOwnProperty("username")) {
            connectOptions.username = options.username;
        }

        if (options.hasOwnProperty("password")) {
            connectOptions.password = options.password;
        }

        if (options.hasOwnProperty("bucket")) {
            connectOptions.bucket = options.bucket;
        }

        if (options.hasOwnProperty("cachefile")) {
            connectOptions.cachefile = options.cachefile;
        }

        if (options.hasOwnProperty("connectionTimeout")) {
            connectOptions.connectionTimeout = options.connectionTimeout;
        }

        if (options.hasOwnProperty("operationTimeout")) {
            connectOptions.operationTimeout = options.operationTimeout;
        }


        if (options.hasOwnProperty("db")) {
            connectOptions.db = options.db; // DB Instance
        }

        if ( typeof(connectOptions.db) != 'undefined' ) {
            this.client = connectOptions.db;
        } else {
            var Couchbase = require('couchbase');
            var cluster = new Couchbase.Cluster(connectOptions.host);

            var bucket = connectOptions.bucket;
            var prefix = this.prefix;

            this.queryAll = Couchbase.N1qlQuery.fromString('SELECT `'
                + bucket + '`.* FROM `'
                + bucket + '` WHERE SUBSTR(META(`'
                + bucket + '`).id, 0, '
                + prefix.length + ') = "'
                + prefix + '"');

            this.client = cluster.openBucket(connectOptions.bucket, connectOptions.password, function(err) {
                if (err) {
                    console.log("Could not connect to couchbase with bucket: " + connectOptions.bucket);
                    self.emit('disconnect', err);
                } else {
                    self.emit('connect');
                }
            });
        }

        this.client.connectionTimeout = connectOptions.connectionTimeout || 10000;
        this.client.operationTimeout = connectOptions.operationTimeout || 10000;

        this.ttl = options.ttl || null;
    }
function CouchbaseStore ( options ) { var self = this ; options = options || { } ; Store . call ( this , options ) ; this . prefix = null == options . prefix ? 'sess:' : options . prefix ; var connectOptions = { } ; if ( options . hasOwnProperty ( "host" ) ) { connectOptions . host = options . host ; } else if ( options . hasOwnProperty ( "hosts" ) ) { connectOptions . host = options . hosts ; } if ( options . hasOwnProperty ( "username" ) ) { connectOptions . username = options . username ; } if ( options . hasOwnProperty ( "password" ) ) { connectOptions . password = options . password ; } if ( options . hasOwnProperty ( "bucket" ) ) { connectOptions . bucket = options . bucket ; } if ( options . hasOwnProperty ( "cachefile" ) ) { connectOptions . cachefile = options . cachefile ; } if ( options . hasOwnProperty ( "connectionTimeout" ) ) { connectOptions . connectionTimeout = options . connectionTimeout ; } if ( options . hasOwnProperty ( "operationTimeout" ) ) { connectOptions . operationTimeout = options . operationTimeout ; } if ( options . hasOwnProperty ( "db" ) ) { connectOptions . db = options . db ; // DB Instance } if ( typeof ( connectOptions . db ) != 'undefined' ) { this . client = connectOptions . db ; } else { var Couchbase = require ( 'couchbase' ) ; var cluster = new Couchbase . Cluster ( connectOptions . host ) ; var bucket = connectOptions . bucket ; var prefix = this . prefix ; this . queryAll = Couchbase . N1qlQuery . fromString ( 'SELECT `' + bucket + '`.* FROM `' + bucket + '` WHERE SUBSTR(META(`' + bucket + '`).id, 0, ' + prefix . length + ') = "' + prefix + '"' ) ; this . client = cluster . openBucket ( connectOptions . bucket , connectOptions . password , function ( err ) { if ( err ) { console . log ( "Could not connect to couchbase with bucket: " + connectOptions . bucket ) ; self . emit ( 'disconnect' , err ) ; } else { self . emit ( 'connect' ) ; } } ) ; } this . client . connectionTimeout = connectOptions . connectionTimeout || 10000 ; this . client . operationTimeout = connectOptions . operationTimeout || 10000 ; this . ttl = options . ttl || null ; }
Initialize CouchbaseStore with the given `options`.

@param {Object} options
{
host: 127.0.0.1:8091 (default) -- Can be one or more address:ports, separated by semi-colon, or an array
username: '',   -- Should be same as bucket name, if provided
password: '',
bucket: 'default' (default)
cachefile: ''
ttl: 86400,
prefix: 'sess',
operationTimeout:2000,
connectionTimeout:2000,
}
@api public
Initialize CouchbaseStore with the given options .