Configure Sync_gateway with couchbase-lite Android

Hi ,
I am new at couchbase sync-gateway configuration . I need clear steps for How to add config.json file ? Here is my config.json

“interface”: “:4984”,
“adminInterface”: “:4985”,
“log”: [“REST”],
“databases”: {
“db”: {
“server”: “http://SERVER_IP:8091”,
“users”: {“GUEST”: {“disabled”: false, “admin_channels”: ["*"]}},
“bucket”: “default”,
“sync”: function(doc) {channel(doc.channels);}

Here is output when i start sync_gateway

2017-02-22T08:33:00.797Z Enabling logging: [REST]
2017-02-22T08:33:00.798Z ==== Couchbase Sync Gateway/1.3.1(16;f18e833) ====
2017-02-22T08:33:00.798Z requestedSoftFDLimit >= currentHardFdLimit (5000 >= 4096) capping at 4096
2017-02-22T08:33:00.798Z Configured process to allow 4096 open file descriptors
2017-02-22T08:33:00.798Z Opening db /db as bucket “default”, pool “default”, server SERVER_IP:8091>
2017-02-22T08:33:00.798Z Opening Couchbase database default on <SERVER_IP:8091>
_time=2017-02-22T08:33:00.883+00:00 _level=INFO _msg= Trying with selected node 0
_time=2017-02-22T08:33:00.883+00:00 _level=INFO _msg= Trying with SERVER_IP/pools/default/bucketsStreaming/default
_time=2017-02-22T08:33:00.896+00:00 _level=INFO _msg=Got new configuration for bucket default
_time=2017-02-22T08:33:00.924+00:00 _level=INFO _msg= Trying with selected node 0
2017-02-22T08:33:00.980Z NOTE: “db”'s sync function has changed. The new function may assign different channels to documents, or permissions to users. You may want to re-sync the database to update these.
2017-02-22T08:33:01.137Z Reset guest user to config
2017-02-22T08:33:01.137Z Starting admin server on :4985
2017-02-22T08:33:01.145Z Starting server on :4984 …
2017-02-22T08:33:01.145Z FATAL: Failed to start HTTP server on :4985: listen tcp :4985: bind: address already in use – rest.(*ServerConfig).Serve() at config.go:624

What is the error there ? Can you please explain how to test sync from Android ?

this means your sync function has changed ,all your data in default bucket on http://SERVER_IP:8091 may assign different channels to documents, you can re-sync to update channels for documents.

you can start pull/push sync with sync gateway,and add/modify document from Android and sync gateway, and get change from _changes api by SDK or by REST API.
here is a example for Android, FYI.

Hi, I tried to sync from android .But failed. i tried http://serverip:8091/bucket_name . Can you please tell me why it’s failed?
When i send request this http://server_ip:8091/default Respone is : Not found

what do you mean this?
you should start pull/push sync with sync gateway,and add/modify document from Android ,and then get document from Sync Gateway to verify by access http://<SyncGateway_ServerIP>:4984/db/

Can you tell me How to re-sync for update channels? I am very new at couchbase .

Hi, I tried to re-sync the channel, but it says database must offline to re-sync . Do i must need to re-sync now ?


Hi ,
I added android code for test sync . Here is ther Logs

My Sync url : http:serverip:8091/databasename , is it right?


/Sync: Change tracker stopped during continuous replication
02-22 17:00:38.261 18456-21553/ W/ChangeTracker: ChangeTracker{http://serverip:8091/db, OneShot, @62027f9}: Change tracker got error 404
02-22 17:00:38.261 18456-18701/ W/Sync: Change tracker stopped during continuous replication

Sync url should be


Yes. I added . After that , Logs
d W/Sync: Error converting lastSequence: null to long. Using 0

Here is my start sync Method
public void start_sync_gateway() {

    URL url = null;
    try {
        url = new URL(mSyncGatewayUrl);
    } catch (MalformedURLException e) {

    pusher = database.createPushReplication(url);
    pusher.setContinuous(true); // Runs forever in the background

    puller = database.createPullReplication(url);
    puller.setContinuous(true); // Runs forever in the background


Here is My onCreate Method
protected void onCreate(Bundle savedInstanceState) {

    // Create a manager
    Manager manager = null;
    try {
        manager = new Manager(new AndroidContext(getApplicationContext()), Manager.DEFAULT_OPTIONS);
    } catch (IOException e) {

// Create or open the database named app
//Database database = null;
try {
database = manager.getDatabase(“db”);
} catch (CouchbaseLiteException e) {
// The properties that will be saved on the document
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(“title”, “Couchbase Mobile”);
properties.put(“sdk”, “Java”);
// Create a new document
Document document = database.createDocument();
// Save the document to the database
try {
} catch (CouchbaseLiteException e) {
// Log the document ID (generated by the database)
// and properties
Log.d(“app”, String.format(“Document ID :: %s”, document.getId()));
Log.d(“app”, String.format(“Learning %s with %s”, (String) document.getProperty(“title”), (String) document.getProperty(“sdk”)));


i replaced server key’s value as at config.json file . Is it ok ?

that means your CB server and SG server on the same machine.


ok. But i can’t add any Document at my Bucket. How can i do it ? can you please explain ?

I installed sync_gateway in my cloude server . So, is my config.json file right ? How to call from syncURL . Can you please give me short description ?

that means your CB server and SG server on the same machine.

you can test from SG first by send HTTP request for documents CRUD
for example

curl -X PUT -H "Content-Type:application/json" http://your_cloud_server:4984/db/doc1--data '{"some_key":"some value"}'

then From Android Couchbase Lite,there is also a HTTP REST API you can use.

I got this
{“error”:“Bad Request”,“reason”:“Bad JSON”}curl: (6) Could not resolve host: “some_key”

should be

curl -X PUT -H "Content-Type:application/json" http://your_cloud_server:4984/db/doc1 --data '{"some_key":"some value"}'

Same output
:~$ curl -X PUT -H “Content-Type:application/json” http://ip:4984/db/{doc id}–data ‘{“created_by”:“3”}’
{“error”:“Bad Request”,“reason”:“Bad JSON”}curl: (6) Could not resolve host: “created_by”

there should be at least a Space between {doc id} and --data