Public access to channels

Copied from

Below is my sync gateway function, i want to allow some documents (which has type=“public_access”) to replicate to all users, How do i do that? I added channel as public for those documents, but it does not work.

    "interface": ":4984",
    "adminInterface": ":4985",
    "log": ["CRUD",  "HTTP",  "Access", "Cache", "Shadow", "Changes"],
    "databases": {
        "todo_sync" : {
            "server": "",
            "import_docs": true,
            "users": {        
                "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } },
            "sync": `
                function(doc) { 
                    if(doc.type == "gift_issuers") { 

            "shadow": {
                 "server": "",
                 "bucket": "todo_server"

You’ve got two options in this scenario:

  1. Grant all users access to your “public” channel. This could be done either via the Admin REST API, or by an access grant in your sync function.
  2. Use Sync Gateway’s built-in public channel “!”. Channeling documents to the “!” channel will make them accessible to all users without any additional security required for those users.

Hi Thanks for Reply

My sync gateway File is

“log”: [“CRUD”, “REST+”, “Access”],
“databases”: {
“testdemo”: {
“server”: “http://ravideveloper:8091/”,
“users”: {
“ravi”: {
“disabled” : false,
“password”: “ravi@123”,
“sync”: function(doc, oldDoc) { // NOTE this function is the same across the iOS, Android, and PhoneGap versions. if (doc.type == "task") { if (!doc.list_id) { throw({forbidden : "items must have a list_id"}) } channel("task-"+doc.list_id); } else if (doc.type == "list") { channel("list-"+doc._id); if (!doc.owner) { throw({forbidden : "list must have an owner"}) } if (oldDoc) { var oldOwnerName = oldDoc.owner.substring(oldDoc.owner.indexOf(":")+1); requireUser(oldOwnerName) } var ownerName = doc.owner.substring(doc.owner.indexOf(":")+1); access(ownerName, "list-"+doc._id); } }

@ravisharma99885 Is this related to the previous question? I don’t see any attempts to use public channels in that config.

I will try the public channel and let you know.

Hi Adamf ,

I try the public channel but it give me the** same error**.

How can we have a plain text password in the config file? Is that not a security issue?

@preethi.minti The usual approach is to create users through the admin REST API.

@ravisharma99885 Were you able to get your situation resolved?

Is there an example that you can point me to? Everywhere I see users being configured in the json file that is used to start sync gateway.

If we have an external custom authentication, the same user needs to be created in syncgateway in order to access the CouchbaseServer correct?

@preethi.minti Here’s the documentation for the user-related REST API:

For custom authentication, you’re correct. The usual process is to have your custom auth service attempt to create a session for the user via the REST API, and if that fails, go back and create the user via the REST API. Some additional notes here: