Hi,
I am using couchbase lite 2.0 in iOS i am getting this error. CouchbaseLite Sync ERROR: {Repl#1} Got error response: HTTP 409 ‘Document update conflict’
I used following code for save or update the document.
do {
if try database.saveDocument(doc, concurrencyControl: .lastWriteWins) {
// save was a success. docToSave is the new saved revision. Proceed as usual
}
else {
// Failure on save with failOnConflict mode
// Handle conflict appropriately
print("Document failed with conflicts......")
if let currDoc = database.document(withID: doc.id) {
// Option 2: Examine contents of current saved version of doc
// Force write of document
try database.saveDocument(doc)
}
else {
// Doc was deleted.
// Option 2: Attempt to do a force write of document to override the delete
try database.saveDocument(doc)
}
}
}
catch {
print("Some other error in saving \(error)")
}
Here is my sync config file. which is supports auto conflicts fix as well
Seems sometimes, the otherside app local DB not updating. But i thought following is the issue for conflicts. Because when i get new updated record, i will do some operation again.
database.addChangeListener { [weak self](change) in
guard let `self` = self else {
return
}
for docId in change.documentIDs {
let doc = self.database.document(withID: docId)
print("Doc id is \(docId) and doc is \(doc?.toDictionary()) and \(doc?.sequence)")
if let _doc = doc{
documentlistener?(_doc)
}
}
}
Still didn’t understand why addChangeListener block calling multiple times for same documentid. even when i update a single document one time at a time.
Do we have any other lister to identify what are records changed recently without any duplicated like above. or shall we use liver query for this?
@jens Any update, even sometimes my latest revision is not updated to server.
Here i attached my sync log and admin portal. i didnt understand the root cause.
The Couchbase Lite logs would be the most useful thing to see here. Also, you should specify what document ID is involved.
And please don’t attach logs as screenshots – they’re hard to read and unsearchable. Copy the text and paste it into a gist on Github, and post a link to that.