N1QL queries give me "Segmentation fault (core dumped)" error


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

        console.log("query failed", err) ;
        return ;
    console.log("success!", res) ;


And here’s the console output:

~$ nodejs UpdateGuesses.js
Segmentation fault (core dumped)

The query works fine when I use the command line (cbq). Any ideas about what’s going on?

Kind regards,

Hey @dbergan,

What version of Couchbase Server and what version of the Node.js SDK are you using?


CB Server is 4.0 release candidate.

Couchnode was installed 2 days ago via

sudo npm install couchbase

Let’s see, how do I find the version number again…

npm -v couchbase

oops… that’s the version of npm

ok, I did
npm list


From the couchnode computer, when I do this:

curl http://cb4-server1:8093/

I get this:

404 page not found

However at port 8092 I get:


Hey @dbergan,

Out of curiosity can you remove the following line?:


You shouldn’t need it with the latest Node.js SDK and Couchbase 4.x. Depending on the results, we’ll go from there.


Something new!

Now it says

~$ nodejs UpdateGuesses.js
query failed { [Error: Unable to decode prepared statement - cause: Unrecognizable prepared statement - cause: unable to convert to prepared statment.]
  code: 4070,
  otherErrors: [],
  requestID: '0a0f6c86-a439-44ca-8b03-00deb794a32c' }

We’re doing better :slight_smile:

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.

Let me know how that goes.


You might also try providing an empty array for prepared statement parameters. Example:

myBucket.query(nquery, [], function(err, results) {

Beneficial to you in the future to prevent SQL injection on user defined query parameters.


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.

myBucket.query(nquery, function(err, [], results) {
SyntaxError: Unexpected token [

I get this error regardless of how I handle the META suggestion.

Kind regards,

Hey @dbergan,

The brackets are in the wrong spot. They should come after nquery, but before the function.

bucket.query(query, prepared_parameters_array, callback_function)

Let me know how that works out.


As soon as I posted this, I realized I put the [] in the wrong place. When I put it in the right place, i.e.

myBucket.query(nquery, [], function(err, results) {

I no longer get the syntax error, but still do get the 4070 errors with/without the META suggestions.

Hey @dbergan,

I’m going to pass this issue on to one of our Node.js SDK engineers. I will get back to you as soon as I get a response!


Sounds good. I updated couchnode to the github master.

sudo npm install "git+https://github.com/couchbase/couchnode.git#master"

It’s still giving me the same error.


Heard anything from the engineers yet?

Hey @dbergan,

Thanks for bringing this up again. Let me ping them once more :smile:


Hey @dbergan,

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.

Cheers, Brett

Awesome. Works great now! Thanks so much.

Hey @dbergan, I’m glad our Node.js engineer, @brett19, was able to find the solution!

Reach out in the forums if you need anything else in the future.