How do I check if a query is done?

How do I check if a query is done and the values are saved?

This is my problem. I save a a value in a new document using INSERT. I then SELECT all similar documents. But it seems like the value needs some time to be saved in the document. I made my script sleep for 5 seconds before doing the SELECT. Then everything works.

Couchbase Indexes are maintained asynchronously index update will lag few milliseconds. You can use scan_consistency

You can look at the various graphs on the bucket to see how quickly the indexes are being updated. It should tell you the drain rate, time it took to update, how many updates are waiting, etc.

Under normal usage you really shouldn’t have to wait between the document change and the index being updated - but if you’re running in a low spec VM or container under load it might be slow.

Ok I understand now what the problem is. Thanks for that.

How do I change this query to use scan_consistency=request_plus?

$query = CouchbaseN1qlQuery::fromString('INSERT INTO `bucket` (KEY, VALUE) VALUES ("'.$document_id.'", {"type": "cu", "customer_id": '.$customer_id.'})');
$result = $bucket->query($query);

You can read this example:

The API docs: http://docs.couchbase.com/sdk-api/couchbase-php-client-2.4.5/classes/Couchbase.N1qlQuery.html#constant_REQUEST_PLUS

I tried to run this code after my insert but it don’t work. Did I do something wrong?

$query->consistency(\Couchbase\N1qlQuery::REQUEST_PLUS);
$result = $bucket->query($query);