Updating locally created document with document from the CB Server


When creating a local document on a device with a known ID that will eventually be created on the CB Server (after some business logic and API results), should the newly created document on the CB server be synced with the local document on the device (providing it has the same CB id)?

Secondly, do all the properties on the doc need to be exactly the same? i.e The locally created document has an a property that is specific to the device such as a locally stored file location.


Local doc:

val doc = MutableDocument(id123)doc.setString("downloadUrl", "") doc.setString("localUri", localUri) doc.setString("type", attachment) database.save(doc)

returned doc from CB server when ready
{ id: id123 downloadUrl: "https://exampleurl" type: "attachment" }

I was hoping by to have the documents synced and merged?

If you create a document with same Id on the client and server when they are disconnected from each other (i.e they are not syncing with each other), then the next time they try to sync, there will be a conflict. System will auto resolve conflict for you or you can define your own custom conflict resolver. You can read about conflict resolution here

1 Like

Hi Priya,

Thanks for update. This makes complete since, I think the default resolver is Last Write Wins, so in this case the Document coming from the CB server is simply replacing the local document and blowing away local URI property.

Do you know if you can apply a resolver to a single use case (i.e contentResolver applied to filtered document type) instead of applying it to all documents? I checked the documentation and found the section on Custom Conflict Handlers which looks like you can add the resolver to the document being saved, however it sounds like this is only applied if the document being saved already exists.

In our case we are creating a new document with MutableDocument({knownId}) and then saving this document (locally as the device is offline). If we add a conflict resolver within this save block, when the document coming from the Couchbase server with the same ID is synced (i.e device back online), it should respect this resolver? (in our case to merge the documents)