The CouchDB Replication and Conflicts wiki page suggests using _bulk_docs
with all_or_nothing=true
to forcibly write new versions of documents even if that introduces conflicts on write, but then resolve shortly after on subsequent reads. I've implemented this and conceptually it seems to work OK.
But BigCouch doesn't support all_or_nothing
semantics so writes to bulk docs can return 409 Conflict results. What is the best practice for implementing similar app-level conflict resolution for conflicts introduced by replication in BigCouch? Should I look at write-time conflict resolution instead?
When you ask CouchDB to replicate one database to another, it will go and compare the two databases to find out which documents on the source differ from the target and then submit a batch of the changed documents to the target until all changes are transferred.
Get the revision number of the document to be updated if there is a conflict during attachment and recursively call in-case of a conflict,
$url = "http://couchdb/DATABASE/DOCID/ATTACHMENTNAME?rev=$rev"; curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_PUT, true ); curl_setopt( $ch, CURLOPT_URL, $url ); curl_exec( $ch );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With