Removing documents from CB Lite if a channel is removed from the user or a role they belong to

We use roles to define channels for users in Sync Gateway. I’m pretty sure that the following works (although not 100% sure about #3):

  1. Add a channel to the role -> next time the client replicates (all channels) it gets documents assigned to that channel.
  2. Add a channel to a document -> next time the client replicates, it gets that document (if the user’s role has that channel)
  3. Remove a channel from a document -> next time the client replicates, the document is removed from the device (unless also available via another channel assigned to that user’s role)

However, based on anecdotal testing it appears that the following does not work:
4. Remove a channel from the role -> next time the client replicates, documents assigned to that channel are removed (unless also available via another channel assigned to that user’s role)

Is that expected behavior? If so, it seems we’ll have to implement some workaround.

what you listed in #3 and #4 are expected while you have a pull or push_pull replication. If you only have a push replication, the documents on your local device will not been synced with the sync gateway.

by the way, where did you perform the “remove a channel from a document” or “from the role”? on sync gateway end or on couchbase lite (the device)?

Both removing a channel from a document and removing a channel from a role were done on the sync gateway side. Recent testing indicated that removing a channel from a role didn’t cause those documents to be removed from the device. It’s been a while since we tried removing a channel from a document, but if my memory serves right, that was working. We’ll do some more testing to confirm.

If a document is removed from all of user’s channels, then couchbase lite should auto purge that document from local database.
However if a user (or role) loses access to a channel , then couchbase lite clients are not notified that they no longer have access to the documents in that channel and documents will not be purged automatically from couchbase lite. This enhancement is tracked here

Workaround is defined here: