Sync data with conditions


I am building chat application where mobile app user keeps data on his device. We try to sync only user-related data from the server to client( couchbase server to couchbase mobile ). But from mobile using swift all Bucket is stored from server to mobile internal db. My sync json is

"interface": "",

“adminInterface”: “”,

“pretty”: true,

"log": ["*"],
"databases": {
    "db": {
        "server": "",
        "bucket": "travel-sample",
        "users": {
            "himanshu": {
              "password": "123456",
              "admin_channels": [
            function (doc) {
                channel (doc.channels);



It is possible that server send only related data to mobile for sync.


Use channels to sync only required data from server to device. when starting pull replication on device channels can be mentioned so that only those channels data will sync only.


Here is a sample Sync Gateway config file that assigns documents to specific channels based on “username” property in the document. You assign documents to channels using the channel API.
Once a document is assigned to a channel, you can enforce access control using access API.

  /* Routing */
  // Add doc to the user's channel.
  channel("channel." + username);

  // Give user read access to channel
   if (!isDelete()) {
       access(username,"channel." + username)

On Couchbase lite side, you can optionally request documents belonging to specific channels. If you don’t do that, documents belonging to all channels that user has access to will be replicated.