N1QL和Couchbase上的Node [英] N1QL and Node on Couchbase
本文介绍了N1QL和Couchbase上的Node的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将N1QL与Couchbase的Node.js SDK结合使用.这是我的代码:
I am trying to use N1QL with Node.js SDK of Couchbase. Here is my code:
var config = require('../../config/init');
var N1qlQuery = require('couchbase').N1qlQuery;
var query = N1qlQuery.fromString("SELECT * FROM users");
var db = couchbaseService();
console.log('start');
db.query(query, function(err, result) {
if (err) {
console.log('inside err');
console.log(err);
return;
}
console.log('No error in NIQL');
console.log(result.object);
});
这是错误:
TypeError: Cannot read property 'length' of undefined
at Bucket._query (/vagrant_data/xxxxx/node_modules/couchbase/lib/bucket.js:331:52)
at Bucket.query (/vagrant_data/xxxxx/node_modules/couchbase/lib/bucket.js:607:17)
at module.exports.show (/vagrant_data/xxxxx/api/controllers/udk/UserController.js:33:12)
at routeTargetFnWrapper (/vagrant_data/xxxxx/node_modules/sails/lib/router/bind.js:178:5)
at callbacks (/vagrant_data/xxxx/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/vagrant_data/xxxxx/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at param (/vagrant_data/dataminer/node_modules/sails/node_modules/express/lib/router/index.js:135:11)
at pass (/vagrant_data/xxxxxx/node_modules/sails/node_modules/express/lib/router/index.js:145:5)
at nextRoute (/vagrant_data/xxxxx/node_modules/sails/node_modules/express/lib/router/index.js:100:7)
at callbacks (/vagrant_data/xxxxx/node_modules/sails/node_modules/express/lib/router/index.js:167:11) [TypeError: Cannot read property 'length' of undefined]
请注意,问题不在于连接到bucker或服务器.我使用了.get()和.insert(),它们工作正常.N1QL库中缺少某些内容.有人可以帮忙吗?
Please note,problem is not about connecting to bucker or server. I used .get() and .insert() and they are working fine.something missing in N1QL library. Anybody can Help?
推荐答案
您必须在给定存储桶上启用n1ql:
You have to enable the n1ql on the given bucket:
bucket.enableN1ql(serverUrl+":8093")
更多信息可以在这里找到: http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/Bucket.html#enableN1ql
More can be found here: http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/Bucket.html#enableN1ql
这篇关于N1QL和Couchbase上的Node的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文