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

时间:2014-07-11 12:48:26

标签: node.js connection database-connection couchbase

使用https://github.com/couchbase/couchnode @ v.1.2.4

尝试使用自述文件中的代码连接到CouchBase服务器

var couchbase = require('couchbase');
var cluster = new couchbase.Cluster();
var db = cluster.openBucket('default');

db.set('testdoc', {name:'Frank'}, function(err, result) {
  if (err) throw err;

  db.get('testdoc', function(err, result) {
    if (err) throw err;

    console.log(result.value);
    // {name: Frank}
  });
});

但是我收到以下错误:

db.js:2
var cluster = new couchbase.Cluster();
              ^
TypeError: undefined is not a function
    at Object.<anonymous> (/Users/n/code/time/test/db.js:2:15)
    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
npr:time n$ 

其他详情:

  • 在Mac上运行Couchbase版本2.5.1(服务器似乎工作正常)
  • 节点版本0.10.29(最新)

注意:我们尝试在CouchBase Bug Tracker上搜索:http://www.couchbase.com/issues/issues/?jql=text%20~%20%22typeError%22,以防其他人遇到同样的错误。没有运气。

1 个答案:

答案 0 :(得分:4)

&#34;解决方案&#34;是使用&#34;开发者预览&#34; Couchbase

npm install couchbase@2.0.0-dp1

然后https://github.com/couchbase/couchnode上的所有示例都按预期工作。

请参阅:http://blog.couchbase.com/nodejs-sdk-200-developer-preview