2017-09-22 91 views
0

我在通过Sync Gateway channels拉取数据时出现问题。Couchbase lite不通过Sync Gateway拉通道

我明白channels的方式是它们基本上是一种标签形式,它可以让您以特殊的方式标记文档。

我所试图做的

当我关闭应用程序,删除本地数据库,然后重新打开,我期待所有的设定是在channels文件的应用拉,但没有拉。

设置

我使用Couchbase精简版1.4.0和最新Sync_Gateway。

同步网关的配置文件,我使用的是默认的同步功能:

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

我访问同步网关Couchbase精简版,像这样:

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(); 

每当我创建了一个文件,我想补充channels密钥的值为["config1"]

我的文档的同步信息,现在看起来像:

"_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" 
    } 

我不知道我在做什么错在这里。推到Couchbase服务器工作正常,但我的拉不能。

谢谢。

回答

1

为了将文档同步到另一个设备,登录用户需要将文档的频道添加到用户的频道列表中。在这种情况下,通过增加"admin_channels": ["config1"]

所以同步网关的配置是这样的......

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

据我所知,如果没有指定同步功能,则默认为默认的一个,这是你的建议。 –

+0

我没有意识到这一点。您还需要添加您需要与用户同步的频道。例如“user_channels”:[“config1”]为user1 – combinatorial

+0

那么,工作。看来我误解了一个重要的方面,我不得不更深入地阅读它。编辑你的答案,我会接受它 –

相关问题