Working with N1QL queries
You can perform Couchbase Query Language (N1QL) queries via Couchnode.
To send N1QL queries, you must specify a list of application query hosts through the enableN1ql method (a temporary necessity). After you have done this, you can perform a N1QL query by using the query() method, which accepts a query created through the N1qlQuery class. You receive an array of objects representing the results through your specified callback.
The following example shows how to send a N1QL query:
var N1qlQuery = require('couchbase').N1qlQuery;
var myBucket = myCluster.openBucket();
var query = N1qlQuery.fromString('SELECT * FROM default');
myBucket.query(query, function(err, res) {
if (err) {
console.log(‘query failed’, err);
return;
}
console.log(‘success!’, res);
});
Sample output from the example:
success! [
{ field_name: ‘value’ },
{ field_name: ‘value’ }
]
Note: Unlike ViewQuery type queries, the N1qlQuery type queries are not currently capable of
streaming rows individually, and instead you must always receive the full result once the
query has fully completed.