Setup channel based document sync


I have tested the documents sync from my iOS swift application. I want to test through channel based documents sync. I think, I need to change ‘admin_channel’ to ‘specific channel’ in ‘couchbase-sync-gateway json’ configuration and then set that channel in iOS application and do authentication as well? Please advise, What are the steps involved? Is there any sample and clear documentation available ? Appreciate your guidance.


How you route documents with channels can be done in a few ways. Ultimately, it depends on what you’re trying to accomplish within your app.

Based on what it sounds like you’re trying to do here are a couple of options to look into:

Please reach out if you have any questions, and certainly don’t hesitate to provide more details on the particular workflow you’re trying to create.

Thank you. I think, the second one you gave is what i want. I read about
Still, it is confusing, lot of stuff in the document. I don’t want to create sync function. Can you please give some example below to do that step by step? Instead of star channel, i just need to use some channel? I am only a iOS developer, not Couchbase adminstrator. What are the changes happening on sync-gateway and iOS client application perspective? It would be great if you could give some examples please.

Can I modify sync-gateway json like this todo sample? It creates channels like, user1 and user2 ?

“log”: ["*"],
“databases”: {
“todo”: {
“server”: “walrus:”,
“users”: {
“user1”: {“password”: “pass”, “admin_channels”: [“user1”]},
“user2”: {“password”: “pass”, “admin_channels”: [“user2”]},
“mod”: {“password”: “pass”, “admin_roles”: [“moderator”]},
“admin”: {“password”: “pass”, “admin_roles”: [“admin”]}
“roles”: {
“moderator”: {},
“admin”: {}
“unsupported”: {
“sync”: `

Sure, that’ll work. Then set the channel property in a document to "user1" or "user2" so that the default sync function will add it to that channel and make it visible to that user.

I have a doubt. “user1”: and “admin_channels” value should be same? for ex: I have “user1” for both
“user1”: {“password”: “pass”, “admin_channels”: [“user1”]},

Also, can i see some iOS swift sample to set document to specific channel?

If you want to give every user their own channel, that’s a good way to do it. It will make documents visible to only one user (if you’re using the default sync function.)

Also, can i see some iOS swift sample to set document to specific channel?

The Sync Gateway sync function is in charge of assigning channels, and it can use any logic it wants to for that, so there’s no general answer to your question.

The default sync function looks at the channels property and if its value is a string assigns the doc to that channel; or if the value is an array, it assigns it to each channel listed in the array.

If your server uses that sync function, then in an app just set a property named channels whose value is the channel (or array of channels) you want to assign the document to.

I know this topic is over 2 years old, but this answer is closest to answers I’m looking for. In our project we create custom sync function, that allows user to access to only one particular channel based on document data. Finally, there could be more than 20000 channels for one user, but during sync function, this user will have access to only one channel. I see in documentation there is a guidance limit of 1000 Channels per user, but there is no strict answer, this limit is for sync function (user could sync up to 1000 Channels at once) or it is Database limit, so on the server user could have access for max 1000 Channels