Hi,
I can’t find a node.js example that uses a parameterized N1QL query, and especially, I don’t see one that uses UPDATE and parameters. Here’s mine, but it doesn’t work.
var couchbase = require("couchbase") ;
var N1qlQuery = require("couchbase").N1qlQuery ;
var myCluster = new couchbase.Cluster('cb4-server1:8091') ;
var myBucket = myCluster.openBucket('quote-unquote') ;
var nquery = N1qlQuery.fromString("SELECT META().id AS pkey, quoteid FROM `quote-unquote` WHERE channels = 'fitb-guess' ORDER BY time LIMIT 1") ;
myBucket.query(nquery, function(err, r1) {
if(err) { console.log("ERROR: ", err) ; process.exit(1) ; }
console.log("pkey=", r1[0]['pkey'], " quoteid=", r1[0]['quoteid']) ;
nquery = N1qlQuery.fromString("SELECT META().id FROM `quote-unquote` WHERE channels = 'fitb-guess' AND quoteid = $quoteid") ;
var params = { quoteid:r1[0]['quoteid'] } ;
var params2 = [ r1[0]['quoteid'] ] ;
myBucket.query(nquery, params, function(err, r2) {
if(err) { console.log("ERROR: ", err) ; process.exit(1) ; }
console.log(r2) ;
process.exit() ;
}) ;
}) ;
The console output of the first log is:
pkey= 4fb1d19f3340b78679f20c1b5e96ab90 quoteid= quote000000001
Now, in the final myBucket.query, when I use params (the json object) as show in the above code I get:
ERROR: { [Error: args has to be of type array]
code: 1070,
otherErrors: [],
requestID: 'e7d4be12-5332-4f7e-89d9-cee7c4d741c9' }
However, when I change that to params2 (the array), I get no error, but it’s a blank result. I’m just trying to get the same primary key that I had in the first query using the quoteid as a parameter.
When I put that query in cbq command line:
SELECT META().id FROM `quote-unquote` WHERE channels = 'fitb-guess' AND quoteid = 'quote000000001' ;
It works fine:
"results": [
{
"id": "4fb1d19f3340b78679f20c1b5e96ab90"
}
],
So something’s wrong with the node.js parameters part.
Kind regards,
David