我正在尝试将 N1QL 与 Couchbase 的 Node.js SDK 一起使用。这是我的代码:
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 库中缺少一些东西。有人可以帮忙吗?