Setup: Couchbase Lite Android 1.4.1 - SG 1.4 - CB Server 4.5
In my data model design I made sure that duplicate inputs cannot happen. That is also true if all devices are offline and a user enters the same data on their devices. Then starts syncing.
In my code the document ID will always be created deterministicly, never randomly. The algorithm to create a document ID is in pseudo code:
String hash = createHash("user input");
String documentId = "[userID]::hash";
Document myDocument = myDatabase.getDocument(documentId);
I run into a problem when I delete a document and then create a document with the same documend ID.
The code was
document.putProperties(myProperties);
I didn’t record the error message but tried the update method:
document.update(new Document.DocumentUpdater() {
@Override
public boolean update(UnsavedRevision newRevision) {
Map<String, Object> properties = newRevision.getUserProperties();
newRevision.setIsDeletion(false);
properties.put("name", "some name");
properties.put("channels", "the document channel");
newRevision.setUserProperties(properties);
return true;
}
});
So I set the deletion flag to false. Here’s the documentation: https://developer.couchbase.com/documentation/mobile/1.5/guides/couchbase-lite/native-api/document/index.html#deleting-documents
I get this error message in the logs in Android Studio
W/Sync: {error=forbidden, id=[document id], reason=missing channel access, status=403}: _bulk_docs got an error: com.couchbase.lite.replicator.PusherInternal$6@6807ae5
A deleted document looks something like this:
{
"_deleted": true,
"_sync": {
"rev": "2-b605fde9989c1af924cf5c1dba27ee9d",
"flags": 1,
"sequence": 233,
"recent_sequences": [
188,
233
],
"history": {
"revs": [
"2-b605fde9989c1af924cf5c1dba27ee9d",
"1-be0606803bb579a58b637d5f2080cfca"
],
"parents": [
1,
-1
],
"deleted": [
0
],
"channels": [
null,
[
"[the document channel]"
]
]
},
"channels": {
"[the document channel]": {
"seq": 233,
"rev": "2-b605fde9989c1af924cf5c1dba27ee9d",
"del": true
}
},
"time_saved": "2017-12-20T17:13:34.411526954Z"
}
}
So my question is: How can I create an entirely new document with the document ID of a deleted document