I am looking for a good way to delete a channel and all of its associated documents from the server-side.
The plan it to ensure that no one has access to the channel first, and with the channel is going away along with the documents, I don’t expect to have sync implications, even if things are still cached in the gateways, since no one will be able to access the (no longer existent) channel.
Is this a candidate to be done directly on the database, rather than having to set up an admin user with access to the channel, get all of the document ids in the channel, and then individually delete them via the sync gateway api, which seems to me still doesn’t delete the channel.
A channel only exists when it has documents in it, so deleting the documents will make the channel go away too. There’s no existing feature to do this, so yes, you’ll have to iterate through all the docs in the channel and delete them.
Is it not the case that deleting them through the sync gateway REST API will leave me with the channel still existing and containing a bunch of tombstone documents? Or is my understanding incorrect?
That is why I asked if it would cause problems for the sync gateway to delete the documents directly via the Couchbase Server APIs…
Only if the sync function adds the tombstone revisions to the channel, which it probably won’t because by default those revisions contain nothing but {"_deleted":true}.
Do not, ever use Couchbase Server APIs to modify data in the Sync Gateway bucket. It will totally confuse Sync Gateway, and probably cause an explosion or a vortex into the nether dimensions or something.
I was under the impression that the tombstones have to be added to the channel if you want deletion of a document to be propagated to other users being synced to the document.
I don’t know any way to distinguish this delete (of the entire channel) from a normal delete of a document within the channel (that needs to be synced). The sync function can really only look at the content of the document, and the delete REST call doesn’t give me any way to influence the content of the tombstone in order to distinguish these two cases.
I suppose I can create an admin user to do the delete channel operation, give them a specific role, and use requireRole with a try/catch block to detect if the user has that role to implement variant behaviour without killing the sync.
You can create a custom tombstone by doing a PUT to the document and including "_deleted":true in the body, along with any other properties you want. (In other words, DELETE of a doc is just a custom version of PUT that always uses a body of {"_deleted":true}.)