2014-10-01 60 views
0

我試圖測試couchnode「Couchbase Node.js客戶端」V2.0.0,但它不起作用。錯誤從Node.js使用Couchnode模塊v.2.0.0連接到CouchBase

我有一個couchbase用2桶安裝:默認和啤酒樣品

我按照自述:couchnode

$ npm install couchbase 

在解說的示例工作正常,並顯示正確{名稱: 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但它是不一樣的問題

回答

-1

「Couchbase的Node.js客戶端」 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); 
}); 
+0

在V2中,實際上有很多變化,我使用的示例項目確實使用了新方法 – clood 2014-10-22 07:19:44

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); 
});