Sync with channesl not working in Couchbase lite 2.0 in iOS

Hi, When I try to create a mutable document in iOS with Couchbase lite 2.0 documents are storing into the server and each document i am adding channels property like below.

Here is my iOS replication code.
let targetEndpoint = URLEndpoint(url: URL(string: kSyncEndpoint)!)
let replConfig = ReplicatorConfiguration(database: database, target: targetEndpoint)

        replConfig.replicatorType = .pushAndPull
        replConfig.allowReplicatingInBackground = true
        replConfig.continuous = true
        replConfig.channels = [kiPadBridgePOC]
        replicator = Replicator(config: replConfig)

Here is my syncgateway configuration file

“log”: [“*”],

“databases”: {
“bucketdb”: {
“server”: “http://localhost:8091”,
“bucket”: “bucketdb”,
“username”: “admin”,
“password”: “password”,

  	"users": {
  		"GUEST": {
  			"disabled": true,
  			"admin_channels": ["*"]


But when i try to replicate on other device. documents are not synching. seems replication is not working based on channels.

I dont know where i did a mistake.

It looks like you’re missing a sync function in your sync gateway config. This function sets access control and authorization for your documents.

This tutorial has a helpful example of how to use the sync function:

Thank you for the reply. But we can do that either through sync gateway config or from couchbase lite. i found what i did wrong.

Here is the solution for adding channels list into channels property in the document.

        let channels = MutableArrayObject()
        doc.setArray(channels, forKey: "channels")

There is a default sync function that will sr channels based on the doc’s “channels” property, so that’s not the problem.

The two ways you created the document seem equivalent to me. Both will set the “channels” property to an array with the same string.

The default sync function is:

function (doc, oldDoc) {

Assuming they’re not authenticating as an admin user with access to all the channels wouldn’t their sync function need at minimum:

function (doc, oldDoc) {
   access(doc.user, doc.channels);

The SG config doesn’t seem to have any users defined. Could be done via REST call, but yes, this looks like a potential problem.

But When I added channels to document, like following is not working synch channel feature in Couchbase Lite iOS Swift.

doc.setArray(MutableArrayObject.init(data: ["bridge"])), forKey: "channels")

But, Whereas I added channels to document, like following it is working and documents are synching based on channels which I added to the documents.

let channels = MutableArrayObject()
        doc.setArray(channels, forKey: "channels")

In the document, it was clearly said. we can achieve this by using any one of the following
Using a channels property
Using a sync function