Sync data with conditions


#1

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": "192.168.0.68:4984",

“adminInterface”: “192.168.0.68:4985”,

“pretty”: true,

"log": ["*"],
"databases": {
    "db": {
        "server": "http://192.168.0.68:8091",
        "bucket": "travel-sample",
        
        "username":"himanshu",
        "password":"123456",
        "users": {
            "himanshu": {
              "password": "123456",
              "admin_channels": [
                "*"
              ]
            }
          },
		"sync":`
            function (doc) {
                channel (doc.channels);
            }
        `

		
		
    }
}

}

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


#2

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.


#3

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.