Hypnic Jerk
Hypnic Jerk

Reputation: 1192

Couchbase lite not pulling channels via Sync Gateway

I'm having a problem pulling data via Sync Gateway channels.

The way I understand channels is they are basically a form of tag that will allows you to mark a document in a special way.

What I am trying to do

When I close the application, delete the local db, and then reopen the application, I am expecting all of the documents in the channels that were set to be pulled, but instead nothing is pulled.

Setup

I am using Couchbase Lite 1.4.0 and the latest Sync_Gateway.

Sync Gateways config file, I am using the default sync function:

{
    "databases": {
        "db": {
            "server": "http://127.0.0.1:8091",
            "username": "db",
            "password": "pass",
            "users":{
                "user1":{
                    "password":"pass"
                }
            }
        }
    }
}

I am accessing sync gateway in Couchbase lite like so:

private String[] docChannels = new String[]{
    "channel1",
    "channel2",
};
private String[] configChannels = new String[]{
    "config1",
    "config2",
};

URL url = null;
try {
    url = new URL("http://127.0.0.1:4984/db");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

Replication push = d.createPushReplication(url);
Replication pull = d.createPullReplication(url);
Replication pullConfig = d.createPullReplication(url);

pull.setChannels(Arrays.asList(docChannels));
pullConfig.setChannels(Arrays.asList(configChannels));

pullConfig.setContinuous(false);
pull.setContinuous(true);
push.setContinuous(true);

Authenticator auth = AuthenticatorFactory.createBasicAuthenticator("user1", "pass");
push.setAuthenticator(auth);
pull.setAuthenticator(auth);
pullConfig.setAuthenticator(auth);

push.start();

pullConfig.start();
pull.start();

Whenever I create a document, I add the channels key with a value of ["config1"].

My document's sync info now looks like:

"_sync": {
    "rev": "1-87cdc8c1fd5e0e4ce1a0897cbd47aca1",
    "sequence": 4,
    "recent_sequences": [
      4
    ],
    "history": {
      "revs": [
        "1-87cdc8c1fd5e0e4ce1a0897cbd47aca1"
      ],
      "parents": [
        -1
      ],
      "channels": [
        [
          "config1"
        ]
      ]
    },
    "channels": {
      "config1": null
    },
    "time_saved": "2017-09-22T13:20:43.6061974-05:00"
  }

I am not sure what I am doing wrong here. Pushing to the Couchbase server works fine, but my pulling does not.

Thanks.

Upvotes: 1

Views: 610

Answers (1)

combinatorial
combinatorial

Reputation: 9561

In order for the document to be synced to another device the logged in user needs to have the document's channel added to the user's channel list. In this case by adding "admin_channels": ["config1"]

So the sync gateway config would look like this...

{
    "databases": {
        "db": {
            "server": "http://127.0.0.1:8091",
            "username": "db",
            "password": "pass",
            "users":{
                "user1":{
                    "password":"pass",
                    "admin_channels": ["config1"]
                }
            }
        }
    }
}

Upvotes: 1

Related Questions