Handling CAS errors


#1

The error returned for a CAS mismatch is the same that is returned when trying to insert an already-existing document. The error code is not ambiguous since the CAS option is only accepted (and only makes sense) for documents which already exist.

Is the above statemat always true? We have KeyExistsError even in delete operation?


#2

Reply please!!! :pensive:


#3

@socketman2016 that’s interesting, we do have an open bug for this behavior in the Java client, but I think you’re using the JS client correct?

On Java at least, this only happens when using the subdoc API to insert a document: with non-subdoc you should get a KeyExistsError instead.

As a workaround for now, you can regard a CAS mismatch error as a KeyExistsError, when inserting a doc using subdoc.


#4

but I think you’re using the JS client correct?

Yes , I use NodeJS client

Can you (or any body) verify that In couchnode client it is safe to assume CAS mismatch error as a KeyExistsError and the statement is true regardless of operation,insert,upsert,delete,subdoc


#5

No as mentioned, only when you’re inserting a doc using subdoc is that a safe assumption.


#6

How can I handle CAS mismatch In CRUD ? What error code we have?


#7

How we can inserting a doc using subdoc?? there is no option in nodejs



#8

Well the JS client is outside my wheelhouse tbh (I work on the Java SDK)… paging @brett19


#9

@brett19 can you please reply


#10

Reply please , it is very important question


#11

Hey @socketman2016,

Sorry for the delay in answering this question!

Can you (or any body) verify that In couchnode client it is safe to assume CAS mismatch error as a KeyExistsError and the statement is true regardless of operation,insert,upsert,delete,subdoc

This is nearly true. KeyExistsError will appear for insert when they key exists, regardless of any kind of CAS usage, since CAS is ignored on an insert. In the other cases, the KeyExistsError will appear when a CAS mismatch occurs.

Cheers, Brett