Help with CouchBase and N1QL concept Insert/Update/Select

I need your help with couchbase + n1ql concept insert/update/select in nodejs

I’m working on user application, which is using classic concept
Insert a new doc or update existing doc and then after this action quick read back this new saved doc.
This is my code example for better explanation:

  1. step
    function insertData(){
    db.insert(doc_id, doc, function(err, meta){
    if(err){
    console.log(err);
    } else {
    readData();
    }
    });
    }
  2. step
    function readData(){
    var _sQuery = “SELECT * FROM bucket”;
    db.query(db_n1ql.fromString(_sQuery), function(err, resultset){
    // resultset is empty
    });
    }
  3. step
    i call again this function readData and now is this doc in resultset


so a first time i will try of call function readData right after data are inserted into Couchbase is resultset empty.
When i call this function readData a second time, then resultset return correctly this new inserted doc.
Why is this new inserted doc not on first time properly selected ?
It was very quickly selected and index was not yet updated ?
I think, that for this is in ViewQuery object parameter Update (stale)
but in N1qlQuery ?

Hey Donald,
You are correct, internally N1QL is taking advantage of the view engine when there is no specific index defined. This means that your first query after an operation is likely to be retrieved before the index has been updated. I’m not currently aware of any workaround for this, but I will investigate and get back to you!
Cheers, Brett

Hi Brett, thank you, it is very important for me.