2

我沒有從本地couchbase服務器同步到我的android和IOS應用程序,並且它適用於移動到服務器和服務器到移動。然後我試圖從JAVA Web應用程序插入文件到本地服務器,我成功地做到了這一點。但問題是由java web應用程序插入的文檔不能與ios/android移動應用程序同步。我的Java代碼中插入文檔到本地服務器如下:從java代碼添加文檔不同步與couchbase精簡版

public class CouchBase { 

    public static void main(String args[]) { 
     Cluster cluster = CouchbaseCluster.create("127.0.0.1"); 
     Bucket bucket = cluster.openBucket("test"); 
     JsonObject user = JsonObject.empty() 
       .put("name", "amol") 
       .put("city", "mumbai"); 
     JsonDocument doc = JsonDocument.create("102", user); 
     bucket.insert(doc); 
     System.out.println(doc.content().getString("name")); 
    } 
} 

在這種代碼我已創建了一個桶,然後我已創建了一個JSON對象保持所需的值並通過該對象的JSON文檔和最後插入該文件放入桶中。現在

我的手機端代碼來創建文檔:

Document document = database.getDocument(etId.getText().toString()); 


     Map<String, Object> map = new HashMap<String, Object>(); 
     map.put("name", etName.getText().toString()); 
     map.put("city", etCity.getText().toString()); 


     try { 
      document.putProperties(map); 
     } catch (CouchbaseLiteException e) { 
      Log.e(TAG, "Error putting", e); 
     } 

在這段代碼我只是創建一個文件,並把值了。

我同步代碼如下:

Replication pullReplication = database.createPullReplication(syncUrl); 
     Replication pushReplication = database.createPushReplication(syncUrl); 
     pullReplication.setContinuous(true); 
     pushReplication.setContinuous(true); 
     pullReplication.start(); 
     pushReplication.start(); 

我哪裏做的雙向同步。 我沒有得到我錯在哪裏用java code.please幫我解決了這個問題

回答

0

同步網關沒有跟蹤通過Couchbase-Server java sdk插入的文檔,也不建議直接插入同步數據-gateway bucket通過java-sdk,你可以使用bucket shadowing。

如果你想通過你的web應用程序中插入數據,您可以利用同步網關REST API的調用http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/sync-gateway/rest-api/index.html

+0

但我看到的鏈接,我將從服務器得到什麼響應,但我沒有找到任何代碼如何使用REST API的couchbase sync_gateway.can你給我提供一些示例代碼嗎? –

+0

按照這個鏈接,並通過api http://stackoverflow.com/questions/34200298/androidhow-to-use-couchbase-rest-api-in-android-application/34204010#34204010 –

+0

所以我們需要從哪一方從網站或從android/ios應用程序調用couchbase sync_gateway的REST API? –

0

在寫這篇文章的時候,它不是可以使用由同步使​​用的水桶服務器軟件開發工具包網關。這是因爲當新的文檔修訂版保存在Sync Gateway數據庫中時,它會通過同步功能將文檔路由到頻道並授予用戶和角色訪問頻道的權限。其中一些元數據在Couchbase服務器中的文檔中的_sync屬性下保留。服務器SDK當前不知道基於修訂的系統,因此它將更新文檔上的字段而不創建新的修訂。

從Java Web應用程序讀取/寫入Sync Gateway數據的推薦方式是使用Sync Gateway REST API

相關問題