使用Couchnode模块v.2.0.0从Node.js连接到CouchBase时出错

时间:2014-10-01 05:01:06

标签: node.js couchbase couchnode

我正在尝试测试couchnode" Couchbase Node.js客户端" V2.0.0但它不起作用。

我安装了2个存储桶的 couchbase :默认和啤酒样本

我遵循自述文件:couchnode

$ npm install couchbase

README中的示例工作正常并正确显示{name:Frank}

但是当我启动example.js时,它不起作用

我尝试将config.json清空并配置

{ "bucket":"default", "host":"127.0.0.1:8091"}

$ node example.js

/home/clodio/node/node_modules/couchbase/example.js:16
bucket = new couchbase.Connection(config, function(err) {
         ^
TypeError: undefined is not a function
    at Object.<anonymous> (/home/clodio/node/node_modules/couchbase/example.js:16:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

出了什么问题?

注意:我读过Error Connecting to CouchBase from Node.js using Couchnode module v.1.2.4,但问题不一样

2 个答案:

答案 0 :(得分:0)

来自我在Node.js和Couchbase上的博客http://mycouchbaseblog.blogspot.ie/2014/09/getting-started-with-nodejs-and.html

// load the Couchbase driver and connect to the cluster
var couchbase = require('couchbase');
//no need for parameter if it is localhost
var cluster = new couchbase.Cluster();
var bucket = cluster.openBucket('beer-sample');

//get a record from the database and output the results
bucket.get('new_holland_brewing_company-sundog', function(err, result) {
console.log(result);
 });

答案 1 :(得分:-1)

&#34; Couchbase Node.js Client&#34; V2.0.0 DOCS here

以下代码有效,(v2中有很多变化)

var couchbase = require('couchbase')
var cluster = new couchbase.Cluster('couchbase://xx.x.x.x');
var bucket =  cluster.openBucket('users');
bucket.upsert('document_name', {some:'value'}, function(err, res) {
if (err) {
    console.log('operation failed', err);
    return;
}

   console.log('success!', res);
});