Adding and removing from channel

I want to repeatedly grant and revoke access to a document for specific users. The issue I’m having is that the revoke works but the grant does not seem to. At least the grant only works once, but after the document has been revoked once it seems that access to it can never be granted again.

I can see the channels in the document being updated by the sync_gateway, as far as I can see that’s working perfectly. My server changes the document one way and the channel is added. It changes it in another way and the channel is removed. All fine.

When I remove the channel I can see it appear in the client’s _changes feed with _removed=true flagged as expected. But when the server then changes the document is such a way that the user’s channel is added back in, there’s no update in the changes feed. If I query the CBL db I see the doc looks like this:

{_removed: true, _id: "167c2b48-d1d0-4ff9-967a-12d2185a64b7", _rev: "9-258293b3d7ab79e6613b1a3819c6c398"}

It’s stuck at the old revision. Revision 10-... is the new revision and the client should have access, and looking at the document’s channels in revision 10-... it appear that he does, but the changes feed doesn’t update.

Further more, if subsequently revoke access again, the client DOES get updated with revision 11-..., (another _remove in the _changes feed).

Any idea what’s going on?

EDIT: if i delete my database and re-sync from scratch the document appears.

Ah, answered my own question. I was doing a purge after receiving the first _remove notice in an attempt to keep my database trim. After that it wouldn’t accept the subsequent non removed document.