Just trying to run my first N1QL query via the node.js (couchnode) SDK and it’s spitting an error at me. Basically just used the method from this page.
Here’s my code:
var couchbase = require("couchbase") ;
var N1qlQuery = require("couchbase").N1qlQuery ;
var myCluster = new couchbase.Cluster('cb4-server1:8091') ;
var myBucket = myCluster.openBucket('quote-unquote') ;
console.log("1") ;
myBucket.enableN1ql(['http://cb4-server1:8093/','http://cb4-server2:8093/']) ;
console.log("2") ;
var nquery = N1qlQuery.fromString("SELECT COUNT(META().id) FROM `quote-unquote` WHERE channels = 'e-quote'") ;
console.log("3") ;
myBucket.query(nquery, function(err, results) {
console.log("4") ;
if(err)
{
console.log("query failed", err) ;
return ;
}
console.log("success!", res) ;
});
var nquery = N1qlQuery.fromString("SELECT COUNT(META().id) FROM `quote-unquote` WHERE channels = 'e-quote'") ;
I think the problem might be with your use of the META command. You need to provide a bucket name that you wish to use. What happens if you change your query to the following:
var nquery = N1qlQuery.fromString("SELECT COUNT(META(qu).id) FROM `quote-unquote` AS qu WHERE qu.channels = 'e-quote'") ;
Notice that I gave your bucket an alias and plugged it into the META function.
Suggestion 1 (putting the bucket in the META) results in the exact same error. I attempted it with both the full bucket name quote-unquote and the alias. All resulted in error 4070.
Suggestion 2 (using an empty array) gives me an all new error.
Please install the latest version of the SDK (2.1.1) from npm. There was an issue with statement preparation which would cause issues like you were seeing.