Example for use consistency in N1QL query


#1

Hi, could you please help me properly use of consistency in NodeJS couchbase module ?
Do you have some example for this ?
I need know, how to set scan_consistency to REQUEST_PLUS

Thnx


#2

Hey donaldinos,

Try something like:

var couchbase = require('couchbase');
var Nq = couchbase.N1qlQuery;
...
var query = Nq.fromString('SELECT * FROM default').consistency(Nq.Consistency.REQUEST_PLUS);
bucket.query(query, function(err, res) {
  ...
});

Cheers, Brett


#3

Hi brett,

sry, but i still don’t know why this my example is not working correctly. I use N1QL DP4 and Couchbase 4.0
Check output of this script:

var couchbase = require('couchbase');
var db_n1ql = couchbase.N1qlQuery;

var cluster = new couchbase.Cluster('localhost:8091');

var db_bucket = cluster.openBucket('bucket', 'password', function(err) {
  if(err){
    throw err;
  }
});
db_bucket.enableN1ql('localhost:8093');

  function insert(){
    db_bucket.counter('test::count', 1, {initial: 1 }, function(err, value_doc){
      if(err) {
        console.log(err);
      } else {
        new_doc = {
            name: 'test'
          , status: 1
        }
    
        var doc_id = 'test_' + value_doc.value;
        db_bucket.insert(doc_id, new_doc, function(err, meta){
          if(err){
            console.log(err) ;
          } else {
            select(doc_id);
          }
        });
      }
    });
  }

  function select(id){  
    var _sQuery = "SELECT * FROM bucket WHERE META(bucket).id = '" + id + "'"; 
    console.log(_sQuery);
    var query_string = db_n1ql.fromString(_sQuery).consistency(db_n1ql.Consistency.REQUEST_PLUS);
    db_bucket.query(query_string, function(err, resultset){
      if(err){
        console.log(err);
      } else {
        console.log('immediate select: ');
        console.log(resultset);
        setTimeout(function() {
          console.log('--------------');
          console.log('Timeout 3 sec. select: ');
          select(id);
        }, 3000);
      }
    });
  }

insert();

$ node n1ql_insert_consistency.js
SELECT * FROM bucket WHERE META(bucket).id = 'test_1'
immediate select:
[]
'--------------
Timeout 3 sec. select:
SELECT * FROM bucket WHERE META(bucket).id = 'test_1'
immediate select:
[ { bucket: { name: 'test', status: 1 } } ]

#4

plz. somebody can help me ?


#5

Hey donaldinos,

This looks like an issue with the query engine. Let me see if I can find someone to give you a hand.

Cheers, Brett


#6

hi … any progress ?


#7

Hey brett

do you have some new informations about this issue ?

thnx


#8

Hey donaldinos,

I believe this issue may be fixed in the latest builds, but I am uncertain when there will be a release that includes it. I’ll let you know when I find out!

Cheers, Brett