Creating index via nodejs sdk for n1ql

Hi

Can I please have a comprehensive example of how to:

CREATE INDEX nameIndex on bucketName(fieldName) using GSI;

Using nodejs SDK?

I know the documentation mention the Index class, but it doesn’t appear in the SDK’s classes documentation nor did I find a full example of its use (the example I did find only show how to create the index once you have the Index class).

Thanks

Hey @tzali,

To do a CREATE INDEX with the Node.js SDK, you simply need to execute it similarly to any other query you need to run. Here is a quick example:

var q = couchbase.N1qlQuery.fromString('CREATE INDEX nameIndex on bucketName(fieldName) using GSI');
bucket.query(q, function(err, res) {
  ...
});

That’s odd

I tried that and it threw a parse error.

I’ll try it again per you exact example and get back with the results

Is this expected to be resolved in a more recent versions?
I am trying to create a simple index using the Nodejs SDK and I get the following error:

'CREATE INDEX ’ + name + ’ on ’ + self.bucket._name + ‘(’ + index_key[0] + ‘) USING GSI’


“{“requestID”:“4ffd8d35-4bff-4a75-8daf-a26efc6eb81f”,“code”:5000,“otherErrors”:,“responseBody”:”{\n "requestID": "4ffd8d35-4bff-4a75-8daf-a26efc6eb81f",\n "signature": null,\n "results": [\n ],\n "errors": [\n {\n "code": 5000,\n "msg": "GSI index id c31974bced1d4b98 not found."\n }\n ],\n "status": "errors",\n "metrics": {\n "elapsedTime": "2.0110414s",\n "executionTime": "2.0110414s",\n "resultCount": 0,\n "resultSize": 0,\n "errorCount": 1\n }\n}\n"}"

  • I tried with existing indexes,
  • then I cleaned all of them,
  • got an error primary index does not exist,
  • I added that (primary index to the script, before executing the above create index
    but the problem remains

I manually tried the query in the Dashboard UI and it ran successfully .

I tried playing a bit with the quotation marks, but still with no luck.

sdk version:
“couchbase”: “^2.3.4”,
server version:
Version: 4.6.0-3453 Enterprise Edition (build-3453)
Cluster State ID: 016-010-114

update:
the index is seem to be created, the response is wrong, (callback)