问题
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);
});
Here is the error:
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]
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?
回答1:
You have to enable the n1ql on the given bucket:
bucket.enableN1ql(serverUrl+":8093")
More can be found here: http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.0/Bucket.html#enableN1ql
来源:https://stackoverflow.com/questions/26044397/n1ql-and-node-on-couchbase