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


#1

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?


#2

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.


#3

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:

P1-Jan-2018
P1-Feb-2018
P1-Mar-2018
P1-Apr-2018
P1-May-2018

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:

P1-Apr-2018
P1-May-2018