How to partition the dataset that is synced to Couchbase Lite (via Sync Gateway)


I’m developing a document management app with Couchbase Lite and Sync Gateway.

We have a few thousand documents, and everyone one has a (potentially unique) subset of natural languages assigned to it (Languages are given as an array property for every document in CB. We support around 30 languages overall).

What would be the best way to configure the system so that only those documents that are required on a specific iOS device get synced to it? (Users can select any subset of the languages, and any document that contains at least one of the selected languages needs to get synced.)

The Sync Gateway currently shares an account for all users.

I’ve seen that CBL and Sync Gateway support “filtered pull” but it seems that couldn’t be used in my case because there are potentially billions of combinations of languages and from what I’ve seen it looked like every filtered pull is identified by a name (and the subset is defined by JS function on the server). What would be needed is to pass parameters to the JS function that does the filtering.

I’ve also seen that I could potentially make a channel for every language and add every document to its languages’ channels. But would there be some way to just tell the Couchbase Lite which channels it should pull? (What I’ve seen is that you can use the REST API of the Sync Gateway to assign users to different channels, but that wouldn’t work with the shared Sync Gateway account that I currently use.)

Looking forward to any tips you may have


Tag every document with channels based on its language.
In Couchbase Lite, just set the ‘channels’ property of the Replication object to tell the client which channels to pull.

This document might help with understanding how to dynamically assign channels with the sync function: