Hi there. I’ve been trying to run the Couchbase blog example (https://blog.couchbase.com/using-couchbase-analytics-node-js-javascript/) against my Couchbase 6.0 cluster with no success. I have a 4 node cluster with the analytics service running on it’s own node. Below is the code I’m running along with the resulting error. Note that I can query my ‘airport’ dataset just fine from the Analytics Query Editor…just cannot run the same query from Node.js. I am able to use the CBAS REST API to query successfully (show code after error). Should I just use this instead of the Node.js API to query the analytics service? Do I lose functionality if I had to go this route?
Please help if you can…I’m stuck!
CODE:
var cluster = new Couchbase.Cluster(“couchbase://MY MASTER NODE IP”);
cluster.authenticate(“analytics_reader”,“analytics_reader”);
cluster.enableCbas([“MY ANALYTICS NODE IP:8095”]);
var statement = “SELECT * FROM airport”;
var query = Couchbase.CbasQuery.fromString(statement);
cluster.query(query, (error, result) => {
if(error) {
throw error;
}
console.log(result);
});
RESULT:
Error: You cannot perform a cluster-level query without at least one bucket open.
at Cluster.query (C:\Git\cb_analytics_travel-sample\node_modules\couchbase\lib\cluster.js:398:16)
at Object. (C:\Git\cb_analytics_travel-sample\app.js:11:9)
at Module._compile (module.js:624:30)
at Object.Module._extensions…js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:201:16)
at bootstrap_node.js:626:3
THIS WORKS:
var request = require(“request”);
var options = { method: ‘POST’,
url: ‘http://MY ANALYTICS NODE IP:8095/analytics/service’,
headers:
{ ‘cache-control’: ‘no-cache’,
Authorization: ‘Basic YW5hbHl0aWNzX3JlYWRlcjphbmFseXRpY3NfcmVhZGVy’,
‘Content-Type’: ‘application/x-www-form-urlencoded’ },
form: { statement: ‘select * from airport;’, undefined: undefined } };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});