Search code examples
couchbasecouchbase-lite

Couchbase Lite db conflict exception while updating values


Sometimes when inserting values into a Couchbase Lite database, document.putproperties() method throws Couchbase Lite conflict exception with status code 409. Why is that exception happening?


Solution

  • This happens when you try to save a document that has been altered by a different writer. The document revision you're trying to save is in conflict with the existing document.

    This could happen because you have two paths in your app that write the document. That's usually a bug in managing your threads.

    If you're sure it's not a threading bug in your app, then most likely you're running a replication. Replications run on a separate thread. This means it's possible to have a document altered by the replication in between you retrieving it and writing the altered version.

    Check the Couchbase Lite documentation on Documents. Read through the section on updating documents.