UnsavedRevision.Save(true) with allowConflicts=true throws CouchbaseLiteException with status of "Conflict"

Passing the “allowConflicts” argument as “true” to the UnsavedRevision.Save method still results in an exception that indicates that there is a conflict.

Is this intended behavior? How can I save a document even if there is a conflict?

Go through following blog if you aree using CBL 1.4.1

https://blog.couchbase.com/better-updates-couchbase-lite/

Please make it a habit to mention the versions because different versions got different methods.

The problem occurs when you have 2 (or more) instances of the same document. If you create two separate UnsavedRevision objects from Document A, the first call to UnsavedRevision.Save(allowConflict) wins. The second call on the second instance of the UnsavedRevision.Save(allowConflicts) throws an exception because it does not have a parent revision.

The problem is that passing “true” to the aforementioned method should be allowing the revision to be saved with a conflict, and not throwing an exception.

We using 1.4.1.2 of CBLite .NET.

But then why you should have 2 instances of the same document? Because its one data point and should be updated in sequence else how one will find out which one is the truth. May be in your case multiple threads trying to save the same document.

Even if it is the case then too just before saving the document one should get it and update the property and then save.

The conflict creation should be done by two devices , where one is offline and other is online and then when they save the same document and syncs at sync gateway the conflict occurs. But creating the conflict in the same device is I think a design problem.

Like in good old days for RDBMS we use to keep timestamp field which will automatically update and before updating one used to check whether I am updating the right version or not and if somebody already changed it then the row was get back and business logics were applied to update it or throw some errors.

The same thing should be done even in the case of documents too, else there will be data integrity issues.

I need to understand the use case to see whats happening.