I am using CBLite on Android with multiple devices and a sync gateway. Due to race conditions it is possible that two devices create a document with the same ID.
The sync gateway automatically resolves this conflict but I would like to manually merge the content. The database listener receives the change events which have conflict=true, but I couldn’t find a way to tell CB which revision I actually want.
I guess this should be a pretty easy thing to do, if you know how
Thanks for any help,
Document ids are always unique. But it’s possible to create multiple revisions of a document that could be conflicting.
You can read about conflicts in the Document guide
Also check this presentation from Jens at Couchbase Connect 2014.
There’s a snippet to let the user pick the winning revision in the UI for ToDoLite-Android.
I should probably add a section about it in the readme.
Actually the IDs are the same, because I create the docs with Database.getDocument(String id). The IDs here a unique references. If I used random IDs I could not detect the conflict.
Ideally the first device would create the doc and the second would update it. But when the sync is to slow and the document is not yet synced to the second device, it will create a new one.
When both devices are synced, the newer doc is used by the gateway. The docs have a status value which is the important part of it. So I want to tell the sync gateway not to use the newest, but the one with the highest status.
It will still create a conflict but in this case both conflicting revisions will be first generation revisions.
You can use the
conflictingRevisions getter on the document to get the conflicting revisions and delete the one with the lowest status.