Can we customize the logic for syncing documents from Sync Gateway to CBLite?

There is a Couchbase server bucket that contains location data of a person, let’s say P1, for past one month. The location data is continuously getting added to that bucket as and when the person’s location changes. There is a separate service of mine which pushes this data onto the Couchbase server.

Secondly, there is a CBLite Android application of mine which can sync documents (location data) via Sync gateway. It is configured to receive from a channel which contains only P1’s data.

Below are my requirements:

i. Suppose App is connected now to sync gateway for the very first time. It only wants P1’s location data that is received now onwards. In other words, whole one month’s location data is not needed to be synced. Right now, it is syncing whole location data.

ii. Suppose App was connected but went offline for a certain duration, then when it comes back online and connects to sync gateway again, location data collected when App was offline also needs to be synced.

How to achieve this?

it all depends on how you design channels and assign channels to the document.

For instance for every 15/30/60 minute data there can be a channel for each person. And app should keep on changing the channel in the pull replication.

When it goes offline it can find out which channel last time I synced and after that it can listen to all channels onwards.

But this will mean restarting the sync with different channels after some time.

You can only play with channels to have filtered replication.

You will probably have to devise your own scheme for partitioning the channel based on “time slice buckets”. For example, if you typically sync location data in monthly increments, instead of having a P1 channel, you could have:


and the CBLite application could use the current date to setup the replication to subscribe to the appropriate channels. For example, if your business logic was “Sync the last two months worth of data”, then you would subscribe to: