Concurrent updates exception

Hi @graham.pople , @vsr1
suppose document is "{
“hote1”:{
“city”:“Delhi”
},
“hotel2”:{
“city”:“Bangalore”
}
}

when i write update myucket set hotel1.city=“Bangalore” where hotel1.city=“Delhi”
will updates on hotel1 and concurrent updates like this on hotel2
will result in concurrent update exception
or its equivalent to subdoc APIs

Getting this error:
[{“msg”:“DML Error, possible causes include CAS mismatch or concurrent modificationFailed to perform update - cause: MCResponse status=KEY_EEXISTS, opcode=SET, opaque=0, msg: Data exists for key”,“code”:12009}

N1QL update is full document update. Concurrent update of same document can result in cas mismatch and you need to retry again.

Hi @vsr1
yes it makes sense, if i start using sub doc API for update. It will eliminate this issue right.
But i am windering is it possible to make conditional update
like update only when “hotel1.city”=“Delhi”

use subdoc get hotel1.city with cas. If it is “Delhi” do subdoc update else ignore. The check must be done in client.

DocumentFragment result = bucket.mutateIn(id)
.upsert(subDocId, object)
.withCas()
.withExpiry(expiry);
what will be cas here

You should check API’s i am not expert in SDKs. or post in SDK section

Multi document updates checkout JAVA SDK transactions https://blog.couchbase.com/couchbase-brings-distributed-multi-document-acid-transactions-to-nosql/

Okay, Thanks @vsr1 . Will check document