2017-09-22 129 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

那麼,工作。看來我誤解了一個重要的方面,我不得不更深入地閱讀它。編輯你的答案,我會接受它 –