Using sync_gateway

You don’t have to create a channel explicitly. It’s kind of like a tag. If you add a document to a channel by calling channel(...) in the sync function, the channel now exists. From the docs:

You do not need to register or preassign channels. Channels come into existence as documents are assigned to them. Channels with no documents assigned to them are empty. *

Generally no. You use the Sync Gateway admin API to manage users, as described in the docs:

You manage accounts by using the Admin REST API.This interface is privileged and for administrator use only. To manage accounts, you need to have some other server-side mechanism that calls through to this API.

We don’t define your user registration process, so you’d probably have your own app server to manage registration from the app, which then calls Sync Gateway to create the user account.

(curl is a command-line tool for sending HTTP requests. Type man curl at a Terminal command prompt to find out more.)

1 Like

@jens Yeah, I’ll keep reading then. Since English is not my first language I might have missed some important points while reading the docs…Sorry for that. :slight_smile: Thanks for the explanation.

I know our docs are sort of confusingly structured, too; sorry about that! If you find something hard to understand or in the wrong place (or missing), please use the “Feedback” button at the bottom of the docs pages to let us know.

@jens Okay, I’ll keep that in mind. :slight_smile:

Now, after reading your comments, I changed my config to this in order to create channels :

{  "interface":":4988",
  "adminInterface":":4989",
  "log":["CRUD+", "REST+","Access", "Changes+", "Attach+", "Shadow"],
  "databases":{
    "sync_gateway":{
        "server":"http://host:8091",
        "bucket":"sync_gateway",
        "sync":`
                function(doc, oldDoc) {
if(doc.type == "mainForums")
{
channel("main"+doc.id);
}
else if(doc.type == "popularForums")
{
channel("popular"+doc.id);
}
else if(doc.type == "newestForums")
{
channel("newest"+doc.id);
}
  access(android, "newest"+doc.id);
  access(ios, "popular"+doc.id);
channel(doc.channels);
            }`,
        "users": {
                "GUEST": {
                    "disabled": true
                }
            },
        "shadow": {
                "server": "http:/host:8091",
                "bucket": "default"
        }
    }
  }
}

After running that config I was expecting these null values (it is my sync_gateway bucket’s doc btw) to change. What am I missing again?

I didn’t create “channels” key-value propety in the docs of my default bucket. Should I do that also? I didn’t do it because in the sync_gateway bucket docs already have that property somehow.
Thanks.

That sync function seems weird, in that you’re putting every document into a unique channel by itself. Why wouldn’t you just have channels named main, popular, etc? (But I don’t really know what your application does.)

Also, did you mean to keep the channel(doc.channels); line? That’s really just there as a placeholder for experimenting. You wouldn’t normally use that, since it lets a client put any doc into any channel they want.

You didn’t show all of the document’s properties in the screenshot so I don’t know what channels it should have ended up in. But be aware that editing the sync function doesn’t update all the existing documents, because that can take a very long time with a large database — if you want that to happen you need to POST to /db/_resync (see the API docs.)

@jens Okay,this is all of one document in the sync_gateway bucket:

{
  "_sync": {
    "rev": "4-55ad8fbd8817ee6eba91a71cb17b0b28",
    "sequence": 5523,
    "recent_sequences": [
      945,
      962,
      1912,
      2859,
      4268,
      4568,
      5523
    ],
    "history": {
      "revs": [
        "2-27994c7e39b95e6943869590c486ab51",
        "4-55ad8fbd8817ee6eba91a71cb17b0b28",
        "3-e0b9abbfb754361f659a9e730b42ceec",
        "1-9abd012beb4d6415a619a86bb12e7b9a"
      ],
      "parents": [
        3,
        2,
        0,
        -1
      ],
      "channels": [
        null,
        null,
        null,
        null
      ]
    },
    "upstream_cas": 1461144244269416400,
    "upstream_rev": "4-55ad8fbd8817ee6eba91a71cb17b0b28",
    "time_saved": "2016-04-20T12:24:59.6725557+03:00"
  },
  "allowPoll": 0,
  "allowSubscribe": 0,
  "allowUpload": 0,
  "allowVote": 0,
  "avarageColor": "http://icon.donanimhaber.com/mobile-forum-icons/1.png",
  "blogHit": 0,
  "categoryId": 0,
  "childForums": null,
  "customFlood": 0,
  "deleteRight": 0,
  "description": "Donanım / Hardware",
  "downRestriction": 0,
  "enableRating": 0,
  "forumExtra": null,
  "forumsAll": [],
  "forumsTree": [],
  "groupPermissionOn": 0,
  "guestRight": 0,
  "guestUpload": null,
  "hasChild": true,
  "hasProperty": false,
  "iconPath": "1.png",
  "id": 1,
  "isFavorite": false,
  "isForum": false,
  "isModerated": 0,
  "isPrivate": false,
  "lastModified": null,
  "lastModifiedTime": "0001-01-01T00:00:00",
  "lastTopic": null,
  "level": 1,
  "levelOrder": null,
  "linkAddress": null,
  "linkTarget": 0,
  "mPostCount": 0,
  "memUpload": null,
  "memberRight": 0,
  "messageCount": 0,
  "messageCountThisWeek": 8476,
  "modOnUpload": 0,
  "modUpload": null,
  "moderator": [],
  "moderatorName": null,
  "needRevision": 0,
  "noImageInPosts": 0,
  "order": 0,
  "parent": 0,
  "parentName": null,
  "pgdCode": 0,
  "privateUser": null,
  "privateUserRight": 0,
  "redirects": 0,
  "repMode": 4,
  "sMode": 0,
  "sort": 0,
  "sortOrder": 0,
  "themeId": 0,
  "timeFilter": null,
  "title": "Donanım / Hardware",
  "topicCount": 0,
  "topicCountThisWeek": 995,
  "topics": null,
  "ttPaging": 0,
  "type": "mainForums",
  "upRestriction": 0,
  "uploadNumber": 0
} 

I changed my config to that :

{  "interface":":4988",
  "adminInterface":":4989",
  "log":["CRUD+", "REST+","Access", "Changes+", "Attach+", "Shadow"],
  "databases":{
    "sync_gateway":{
        "server":"http://host:8091",
        "bucket":"sync_gateway",
        "sync":`
                function(doc, oldDoc) {
if(doc.type == "mainForums")
{
channel("main");
}
else if(doc.type == "popularForums")
{
channel("popular");
}
else if(doc.type == "newestForums")
{
channel("newest");
}
  access(android, "newest");
  access(ios, "popular");
            }`,
        "users": {
                "GUEST": {
                    "disabled": true
                }
            },
        "shadow": {
                "server": "http://host:8091",
                "bucket": "default"
        }
    }
  }
}

Still there isn’t any channel created, properties are null. Is something missing here? I couldn’t figure it out.

Old post I know, but the answer is also in the docs (I also had this issue):
You need to call _resync, after _offline, followed by _online