Using sync_gateway

It sounds like you’re not passing the config file as a command line parameter (as @andy described above).

@adamf I can’t write anything on the window that I sent picture of in my first post. Should I write it somewhere else?

That shell/command window is running Sync Gateway; it’s a server process, not interactive, so it’s not going to respond to keyboard input.

Open another shell/command window and do it there.

@jens @adamf @andy ok thank you so much . now it saw the changes. I did something and It said :

2016-04-15T15:26:52.564+03:00 FATAL: Failed to start HTTP server on http://syncGatewayIP:4984: listen tcp: too many colons in address http://syncGatewayIP:4984 -- rest.(*ServerConfig).serve() at config.go:591

It says that when I enter couchbaseServerIP instead of syncGatewayIP too.

I edited the post like million times, everytime I try something else,and there were 2 doc in my sync_gateway before I started work with it, now after I did something it became three, _sync:user: appeared but I dont get what it is :

My serviceconfig file is :
{
“log”: [“HTTP+”],
“adminInterface”: “http://couchbaseServerIP:4985”,
“interface”: “http://syncGatewayIP:4984”,
“databases”: {
“sync_gateway”: {
“server”: “http://couchbaseServerIP:8091”,
“users”: {
“GUEST”: {“disabled”: false, “admin_channels”: ["*"] }
}
}
}
}
I want all my docs in default bucket to be synced here. am I doing something wrong with the part I wrote in bold?? My boss said sync_gateway’s IP is different from couchbase server’s IP, shouldnt I use it there also? When I replace them with 127.0.0.1:4984 and127.0.0.1:4985 it just stays lke that:

2016-04-15T13:21:13.741+03:00 Starting server on 127.0.0.1:4984 …

when i use

{
  "log": ["*"],
  "databases": {
    "sync_gateway": {
      "server": "http://couchbaseServerIP:8091",
      "bucket": "default",
      "users": { "GUEST": { "disabled": false, "admin_channels": ["*"] } }
    }
  }
}

it says for evey single doc I got:

WARNING: changeCache: Error unmarshaling doc "mainForums_698": <nil> -- db.(*changeCache).DocChanged.func1() at change_cache.go:327

I’m so stucked.Thanks.

@HandeBc

The appearance of the _sync docs means that Sync Gateway has successfully connected to the Couchbase server bucket.

The error regarding colons is caused by the aminInterface and interface values, these should not include the http:// protocol, also to be clear these must point to the IP address of the local server Sync Gateway is running on, not the IP that Couchbase Sever is running on.

From your post try a serviceconfig.json like this:

{
    "log": ["HTTP+"],
    "adminInterface": "syncGatewayIP:4985",
    "interface": "syncGatewayIP:4984",
    "databases": {
        "sync_gateway": {
            "server": "http://couchbaseServerIP:8091",
            "bucket":"sync_gateway",
            "users": {
                "GUEST": {"disabled": false, "admin_channels": ["*"] }
            }
        }
    }
}

@andy I tried exactly what you wrote, It said :

FATAL: Failed to start HTTP server on syncGatewayIP:4985: listen tcp syncGatewayIP:4985: bind: The requested address is not valid in its context. – rest.(*ServerConfig).serve() at config.go:591

@HandBc

Are you replacing syncGatewayIP with an actual IP bind address.

e.g.

0.0.0.0 (bind to all local interfaces, completely public access to REST API’s)
127.0.0.1 (bind to local loopback interface, only access REST API’s )

{
    "log": ["HTTP+"],
    "adminInterface": "127.0.0.1:4985",
    "interface": "127.0.0.1:4984",
    "databases": {
        "sync_gateway": {
            "server": "http://couchbaseServerIP:8091",
            "bucket":"sync_gateway",
            "users": {
                "GUEST": {"disabled": false, "admin_channels": ["*"] }
            }
        }
    }
}

@andy SORRY for asking too much but gotta say that : mobile side will be handled by some other guys here, my only duty now is to carry my docs from default bucket to sync_gateway bucket and keep these two synchronized… I guess I am struggling with more than I should??
Because my boss just came in and said I shouldn’t be using sync_gateway.exe and all other stuff, it’s already connected and the rest is mobile guys’ thing. Should I write my problem with .net tags or am I in the right place? Because nothing I’ve been doing in this 2 days worked for me, about carrying my docs!

Have you read the docs? The documentation of the config file, linked from the main setup page @adamf pointed you to earlier, shows the format of the file including the "interface" and "adminInterface". This could have saved you a lot of trouble.

1 Like

@jens One more thing, should I be using sync_gateway’s config file to create users? Because I need to create channels and roles so I can’t do that without creating users. But when I look at the documentation it shows codes starting with “curl” and I don’t know what that is. I only use .net SDK and couchbase console, ios and android entegration will be done by someone else. So, could you help me about creating users with the config file? Like, with a sample code or something else?

Thanks

I added 2 users by httpie, like : http PUT :4985/db/_user/ios name=ios password=1234

now I need to create channels and give users authorization. problem is, I really couldn’t get the idea of channels. In my sync_gateway bucket, my docs have this property:

"channels": [
               null,
               null,
               null,
               null
           ]

How should I create channels? Should I go to views tab and create multiple channels, is that the way? Because there is a “channels” view in my sync_gateway’s production views and there are so many mapping codes in it but I didn’t create it. This is also what I should do? Or what? Also, when I create channels, will I change these "null"s by hand? Thanks!

@HandeBc

I would recommend reading all the documentation on Sync Gateway to get a good overview.

There are docs specifically covering channels and the [Sync Function API](http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/sync-function-api-guide/index.html()

There are example Sync Gateway Configuration files

You can also look at one of the ToDoLite mobile applications

iOS
Android
ToDo-Lite-ionic

To see how it interacts with the ToDoLite example config for channels and user access

@andy I read all the docs! Also, mobile applications parts mean nothing to me because I have no idea about ios or android programming. I won’t do that parts at all, someone else will. So all I’m saying is, these docs don’t give any information about “creating” channels, they just show how to use and do things on “created” channels. Hence I’m stuck at the very beginning. My above questions are all about the fundamentals of creating channels and how to shape them in my head. Should I think of them as regular views, or something etc… Thanks again!

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