N1QL and Node on Couchbase

牧云@^-^@ 提交于 2019-12-25 03:19:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!