Issues pulling from couchbase server

I am trying to test couchbase lite, sync gateway and server by performing a simple pull replication from the server to my couchbase lite java native code using the below code.

package com.example;

import com.couchbase.lite.Database;
import com.couchbase.lite.Document;
import com.couchbase.lite.Manager;
import com.couchbase.lite.replicator.Replication;
import com.couchbase.lite.replicator.Replication.ReplicationStatus;
import com.couchbase.lite.JavaContext;
import com.couchbase.lite.util.Log;


public class TestSyncGateway {
    public static String TAG = "TestSyncGateway";

    public static final String DATABASE_NAME = "ships";
    //couch internals
    protected static Manager manager;
    private static Database database;
    private static Replication pull;
    public static void main(String[] args) {
        try {
        } catch (Exception e) {
        System.out.println("Status: " +pull.getStatus());
        while(pull.getStatus() == ReplicationStatus.REPLICATION_ACTIVE) {

        System.out.println("Document count: " +database.getDocumentCount());
        System.out.println("Status: " +pull.getStatus());
    private static void startCBLite() throws Exception {
        Manager.enableLogging(TAG, Log.VERBOSE);
        Manager.enableLogging(Log.TAG, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_SYNC_ASYNC_TASK, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_SYNC, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_QUERY, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_VIEW, Log.VERBOSE);
        Manager.enableLogging(Log.TAG_DATABASE, Log.VERBOSE);
        manager = new Manager(new JavaContext("data"), Manager.DEFAULT_OPTIONS);
        database = manager.getDatabase(DATABASE_NAME);

    private static URL createSyncURL(boolean isEncrypted){
        URL syncURL = null;
        String host = "http://localhost";
        String port = "4984";
        String dbName = "ships";
        try {
            syncURL = new URL(host + ":" + port + "/" + dbName);
        } catch (MalformedURLException me) {
        return syncURL;
    private static void startReplications() {
        pull = database.createPullReplication(createSyncURL(false));

I have configured and started my sync gateway as per below

   "log":["CRUD+", "REST+", "Changes+", "Attach+"],
         "sync":`function(doc) {channel(doc.channels);}`,
		 "users": {
                "GUEST": {
                    "disabled": false,
                    "admin_channels": ["*"]

I have 12 documents in the ships data bucket on the server but after running the above code I get something like

Documents: 0

I’m not sure why the pull isn’t working? I can see the following in the sync_gateway console.

2015-08-24T15:11:29.355+01:00 HTTP:  #021: GET /ships/_local/47f26f56faf66ebac05
2015-08-24T15:11:29.356+01:00 HTTP: #021:     --> 404 missing  (1.0 ms)
2015-08-24T15:11:29.433+01:00 HTTP:  #022: POST /ships/_changes
2015-08-24T15:11:29.433+01:00 Changes: MultiChangesFeed({*}, {Since:0 Limit:0 Co
nflicts:true IncludeDocs:false Wait:false Continuous:false Terminator:0xc08211ac
00 HeartbeatMs:300000 TimeoutMs:0}) ...
2015-08-24T15:11:29.434+01:00 Changes+: MultiChangesFeed: channels expand to cha
nnels.TimedSet{"*":0x1, "!":0x1} ...
2015-08-24T15:11:29.434+01:00 Changes+: MultiChangesFeed sending &{Seq:1 ID:_use
r/GUEST Deleted:false Removed:{} Doc:map[] Changes:[] Err:<nil> branched:false}

2015-08-24T15:11:29.435+01:00 Changes: MultiChangesFeed done
2015-08-24T15:11:29.517+01:00 HTTP:  #023: POST /ships/_changes
2015-08-24T15:11:29.517+01:00 Changes: MultiChangesFeed({*}, {Since:1 Limit:50 C
onflicts:true IncludeDocs:false Wait:true Continuous:false Terminator:0xc08211b3
20 HeartbeatMs:300000 TimeoutMs:0}) ...
2015-08-24T15:11:29.518+01:00 Changes+: MultiChangesFeed: channels expand to cha
nnels.TimedSet{"!":0x1, "*":0x1} ...
2015-08-24T15:11:29.518+01:00 Changes+: MultiChangesFeed waiting...
2015-08-24T15:11:29.519+01:00 Changes+: Waiting for "ships"'s count to pass 0

I can also see the following output by the couchbase log utility

WARNING: Sync: com.couchbase.lite.replicator.PullerInternal@759e008: Received in valid doc ID from _changes: {seq=1, id=_user/GUEST, changes=[]}

Any ideas why it doesn’t appear to be replicating?

Hey @paulstat,

Notice you have a database named ‘ships’ but also created a bucket, ‘ships’ Do you have that enabled on Couchbase Server? Have you tried removing the bucket key and its value?

Can reference the Add Sync Gateway and Bi-Directional Replication document

How did you create the 12 documents on the server bucket?

They need to be created via sync gateway, not directly in couchbase server.

I loaded them using the cbdocloader tool on the server

Yeah, that won’t work. We do have something called "Bucket Shadowing"
which would would allow that to work, however I wouldn’t recommend using it
as there is a long term deprecation plan.

Can you delete those documents from the bucket and add them via the Sync
Gateway REST API?

Ah ok thanks, I shall take a look a the REST API. How do relational keys
(what’s the terminology are they composite keys?) work via sync
gateway/couchbase lite? Eg I had json written like so which I loaded with
the cbdocloader tool.

‘beer_id’ : ‘beer_Hoptimus_Prime’,
‘type’ : ‘beer’,
‘brewery’ : ‘brewery_Hoppy_Brewery’

‘brewery_id’ : ‘brewery_Hoppy_Brewery’,
‘type’ : ‘brewery’
What’s the equivalent way of relating documents through sync
gateway/couchbase lite?