Update with USE KEYS in N1QL not showing mutationCount

I am currently trying to run the following query through the java sdk.

//just filtering the keys and putting them in a jsonArray
List<String> keys; 
JsonAray jsonArray; = JsonArray.create();
keys.stream().filter(docId!=null && !docId.isEmpty()).forEach(docId ->jsonArray.add(docId)));

//setting up the query and positional parameters
String query = "UPDATE `bucket` USE KEYS $1 SET status= $2"
QueryOption 10 = QueryOption.queryOptions().parameters(JsonArray.from(jsonArray,"status");
QueryResult result = cluster.query(query,qo)
return result.metaData().metrics().get().mutationCount();

When I run this, I am getting a java.util.NoSuchElementException: No value present when trying to access the mutationCount even though the query runs without failing (but the update doesn’t work either way since when I check the doc the status remains unchanged). What is wrong with my update statement?

As a follow up, is the only difference between using something like “USE KEYS keys” vs where docId IN keys a matter of performance?

You need to add metrics(true) to your query options to get metrics. (it’s the .get() on the optional metrics() that is telling you there is NoSuch(metrics)Element )



As for no update being done - it looks like it should work. Maybe keys is empty , or there are no documents that match.

[Edited to remove stuff clarified by vsr1]

If you want to be really efficient, use the kv api and mutateIn(). Sub-Document Operations | Couchbase Docs

1 Like

If you know keys then use USE KEYS.
without USE KEYS query must do indexScan that whole step will add up (Also need to have matching index)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.