Sync Gateway: Filtering out expired documents in _changes feed

Hello,

in my application, I make heavy use of sync gateway’s document expiration in order to keep the amount of documents a client receives reasonable. I discovered that using ?show_exp=true, the sync gateway does not return expired documents on GET and bulk_get. However, in the changes feed these expired documents still appear and neither the show_exp parameter nor active_only=true has an effect. This is bad because a client that synchronizes with the server using _changes has to try to fetch all documents, with some of them being expired. It would be nice if _changes just would not show expired documents, thus potentially saving many requests. Is this somehow possible / planned?

The preferred approach to manage the number of documents a client recieves is to use channels. Expiry works the same as purge - it is intended for obsolete documents that clients shouldn’t be requesting, not for documents that are actively being replicated.

For your use case, it sounds like a more appropriate flow would be to remove the document from the client’s channels at the same time you set a (future dated) expiry value for the document in Sync Gateway. This will trigger a removal notification for the document over the changes feed for clients that replicate prior to the server database expiry.

Thank you for your quick response! The method you describe works well, however it does not perfectly fit my use case:
At the server side, I very often create new documents that act as messages sent to the clients that are connected right now. These messages are only important for a short time span, a minute later, they are useless, thus for clients connecting at later times should not be visible. I thought that document expiry would be great for this purpose, because I can declare at creation time when the document should expire and afterwards I can forget about the message.
In order to remove the document from the user channel (as you said), I would have to create some sort of timer that regularly removes old messages from the users’ channels. It would be nice if this wasn’t necessary (i.e. if _changes had an option to respect document expiration).