Reuse document ID of deleted document

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

You should be able to re-create the deleted document as though it didn’t exist, without needing any workarounds.

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

As you can see from the error description, this is a replicator error, with message “missing channel access”. That implies that CBL created the document, and tried to push it to the server, but Sync Gateway rejected the document because you don’t have access to the channel it’s in. That’s an entirely different problem.

I created a new post under Sync Gateway with reproducible steps: SG rejects newly created document with document ID of deleted document: Channel access missing

I’m not sure why you created a new thread, but I posted an answer there.