Sync gateway remove doc from particular channel

I am creating doc with
document id A and assign it to channel C1 in sync gateway with state property value as S1.
Now on server side, listening to _changes feed to process the doc and changing the state from S1 to S2 and assign that doc to only channel C2.

Problem is the new revision still appears in channel C1 feed. Is there anyway I can remove that doc from Channel C1 so that it no longer appears in _changes feed of that channel?

The document will be in whatever channels your sync function added it to. Every time it’s updated, the sync function is called and every channel() call made by the sync function re-adds the doc to that channel. It will no longer be in any channels that it isn’t re-added to by the sync function.

So in short, if you don’t want it to be in channel C1 anymore, modify your sync function so that when the doc is in state S2 it isn’t added to C1.

I am already doing exactly what you suggested.
Please find below sync function snippet. I am creating event with toBeCreated state and and once it is created I am no longer keeping it in “toBeCreated” channel it still shows in that channel.

Example URL :

if (doc.state === "toBeCreated") { channel("toBeCreated"); }else if (doc.state === "created") { if (oldDoc.state === "toBeCreated") { requireRole("admin"); } var channelName = doc._id; channel([channelName, doc.userId]); access("role:event_viewers", channelName); }

I am also uploading sample document data after created (1.0 KB)
I am using couchbase 4.1 with sync gateway 1.1.1. That is not a problem right?

The revision at which the document was removed from the channel will still be included in the _changes response, with removed=true, to notify clients that they’ve lost access to the document.

If that’s not what you’re seeing, can you share some more information? I wasn’t able to retrieve the sample document data you linked to - it loaded as an empty file.

Thanks Adam,
I can see that changes feed contains “removed”:[“toBeCreated”]
So my only shot not to include the processed doc is to remember the seq, right?

Can you clarify that last question? Where don’t you want the processed doc to be included?

I dont want to include the processed doc in _changes feed if it is removed from that channel. Currently it includes all docs removed from particular channel with removed key as you mentioned.

So If I want that _changes feed should not have the processed doc (Doc which moved from toBeCreated to created state and moved out of channel toBeCreated) then I should remember that last process sequence number and put it in since query param.