Sync gateway remove doc from particular channel


#1

Hello
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?


Purge locally document and avoid pull replication
#2

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.


#3

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 : http://127.0.0.1:4985/XXX/_changes?since=0&channels=toBeCreated&filter=sync_gateway%2Fbychannel&feed=continuous

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 state.EventDoc.txt.zip (1.0 KB)
I am using couchbase 4.1 with sync gateway 1.1.1. That is not a problem right?


#4

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.


#5

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?


#6

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


#7

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.