Hello,
is there a way to use custom filters for the changes feed of sync gateway? As I’ll explain below, I would need a filter that works exactly like sync_gateway/by_channel, but the other way round: I want to sync all documents except those belonging to a single channel.
I need this because I am writing an app that synchronizes using PouchDB and the sync gateway to a couchbase server, where I have two kinds of documents:
- Documents that should be synced (about 100). These documents are in many different channels that change often.
- Documents that should not be synced (a few 10000). These documents should be accessible on-demand, however. They all belong to a single channel ‘doNotSync’.
My first approach to solve this was to use the sync_gateway/by_channel function to sync only documents that belong to channels I’m interested in. The documents of type 2) were fetched on-demand using HTTP GET requests to http://sync_gateway/bucket/documentID
. However, this way the application misses some document updates because the channels change often, as you can see in this example:
- The Application has access to the channels ‘user1’ and ‘user2’, but listens only to _changes filtered by channel ‘user1’
- ‘user2’ publishes something in channel ‘user2’
- the application now listens also to channel ‘user2’
- the document of 2) does not reach the application
Therefore my idea was to sync all documents except those belonging to the channel ‘doNotSync’. In the documentation for the _changes feed I found this option:
filter: “Reference to a filter function from a design document that will filter whole stream emitting only filtered events.”
How can I create a design document with a filter function that I can call? I tried to create a ddoc _design/bar
with the following content
{"filters":{"foo":"function() { ... }"}}
but accessing http://localhost:4985/data/_changes?filter=bla/foo returns “unknown filter”.
Thank you in advance!