1

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.

1 Answer 1

1

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"] } } } } } 
Sign up to request clarification or add additional context in comments.

6 Comments

As far as I'm aware if the sync function isn't specified, it defaults to the default one, which is what you've suggested.
I wasn't aware of that. You also need to add the channels that you require to sync to the user. e.g. "admin_channels": ["config1"] for user1
Well, that worked. It seems that I was misunderstanding an important aspect, I'll have to read more in depth on it. Edit your answer and I'll accept it
It is as above. Based on the docs, developer.couchbase.com/documentation/mobile/current/guides/… it applies it if one is not supplied.
That is one way to do it, but you can also use the access() function inside the sync function to dynamically give users access. If it is meant to be permanent, then using admin_channels is the easiest way though.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.