Cannot select the latest upsert document

Hello,
i’m using Couchbase 5.0 with node SDK, using sync gateway 2.0 with

   "import_docs": "continuous",
   "enable_shared_bucket_access": true,

If i upsert a document and re-execute a select query, the new document is not retrieved.
For example, if i execute this code:

  let query = N1qlQuery.fromString("UPSERT INTO bucket (KEY, VLAUES) VALUES (id, values)")

  await new Promise((resolve) => {
    bucket.query(query, (err, rows) => {
      if (err) {
        console.log('Error executing query')
      }
      console.log('saved')
      resolve()
    })
  })

  /* await new Promise((resolve) => {
    setTimeout(() => {
      resolve()
    }, 1000)
  }) */

  query = N1qlQuery.fromString("SELECT * from bucket where type = type")

  await new Promise((resolve) => {
    bucket.query(query, (err, rows) => {
      if (err) {
        console.log('Error executing query')
      }
      console.log('selected')
      console.log('length ' + rows.length)
      resolve()
    })
  })

The second query has always a length of n-1 document, like the new document not exists in the db.
If i de-comment the timer, the second query now is right, it selects the correct number of document, so the problem is that even if the saving query is resolved, the document is not persisted in the db yet (or at least i think).
In the docs there is nothing about a delay time during saving, so how can i be sure that the document has been saved and so keep going with the other queries?

Thanks in advance

Couchbase indexes are maintained asynchronously it lags few milli seconds behind. You can change scan_consistency if you need immediately.

Hello,
according to the doc, i can set 3 different level. What i need is at_plus.
Would it be a performance problem if i set that consistency as the default one when i execute every query? Or there would be any other problems?

Other than default latencies increase because index needs to wait until specified mutations are applied.

1 Like