Conflict resolving by merging fields on the server

Hi
I have read a lot about handling sync conflicts in Couchbase but all the documentation says it happens on the level of a document. Not on the field level. For example:
User A puts a document on the server
User B gets the same docment
Both users are offline
User A sets field 1 of the document to “A”
User B sets fields 2 of the document to “B”
User A and user B go online and synchronize.

What happens is that 1 change gets lost (the one from User A or B dependend on the sync strategy). But we don’t want that. I guess it should not be the problem to compare the fields on the server and update everything that has changed from a client to the server database.

Sure there is the possibility to handle the conflict manually natively on the client side. But I don’t want to have the logic on the client side. I want to have it on the server side. Is there some buildt-in feature for that? Or do we need to implement that on our own? If yes, I guess the sync function is the right place for that?

Thanks :slight_smile:

Couchbase Mobile doesn’t yet have functionality to merge conflicts at the field/property level. That’s planned for a future release.

You can implement your own server-side merging, but it’ll take some work. You can’t use the sync function, because that function is not allowed to modify the document, only tag it. You’ll need to build a process that watches document changes using the REST API’s “changes feed” and detects conflicts, then fetches the conflicting revisions and saves back a merged version.

Thanks Jens for the answer.