Cannot get Node.js Analytics example to run against 6.0 Server


#1

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);
});


#2

Hey @brian.parker,

Due to an implementation details of our SDKs. It is currently required that you open a bucket prior to performing any queries, even if the queries are run at the cluster level. Sorry for the inconvenience, we are hoping to fix this for the next iteration of our SDKs due early next year!

Cheers, Brett