简体   繁体   English

从Java代码添加的文档未与Couchbase Lite同步

[英]Documents added from java code not syncing with couchbase lite

I did syncing from local couchbase server to my android and IOS application and it is working fine for mobile to server and server to mobile. 我确实从本地Couchbase服务器同步到了我的android和IOS应用程序,并且在移动到服务器以及从服务器到移动的工作都很好。 Then i tried to insert document from JAVA Web application to local server and i succeed to do that. 然后,我尝试将文档从JAVA Web应用程序插入到本地服务器,然后我成功地做到了。 But the problem is that the document inserted by java web application is not syncing with both ios/android mobile applications. 但是问题是Java Web应用程序插入的文档无法同时与ios / android移动应用程序同步。 My java code to insert document to local server is as follows: 我的将文档插入本地服务器的Java代码如下:

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"));
    }
}

In this code i have created one bucket and then i have created one json object holding required values and passing this object to the json document and finally inserting that document into bucket. 在此代码中,我创建了一个存储桶,然后创建了一个包含所需值的json对象,并将此对象传递给json文档,最后将该文档插入存储桶中。

Now my mobile side code to create document: 现在我的移动端代码创建文档:

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

In this code i am simply creating one document and putting values in it. 在这段代码中,我只是创建一个文档并将值放入其中。

My syncing code is as follows: 我的同步代码如下:

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

Where i am doing Bi-directional syncing. 我在哪里进行双向同步。 I am not getting where i am wrong with java code.please help me to out of this problem 我没有弄错Java代码。请帮助我解决这个问题

Sync gateway doesnt track document inserted through Couchbase-Server java sdk,Also It is not advised to directly insert the data in sync-gateway bucket through java-sdk, you can use bucket shadowing for that. 同步网关不会跟踪通过Couchbase-Server java sdk插入的文档,也不建议通过java-sdk将数据直接插入到同步网关存储桶中,您可以为此使用存储桶阴影。

If you want to insert data through your web application you can make use of sync gateway rest api calls http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/sync-gateway/rest-api/index.html 如果要通过Web应用程序插入数据,则可以使用同步网关Rest API调用http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/sync-gateway/rest-api/的index.html

At the time of this writing, it's not possible to use the Server SDKs on the bucket used by Sync Gateway. 在撰写本文时,无法在Sync Gateway使用的存储桶中使用Server SDK。 That's because when a new document revision is saved in a Sync Gateway database it goes through the Sync Function to route the documents to channels and grant users and roles access to channels. 这是因为当新文档修订版本保存在Sync Gateway数据库中时,它会通过“同步功能”将文档路由到通道,并向用户和角色授予对通道的访问权限。 Some of that metadata is persisted under the _sync property in the document in Couchbase Server. 其中一些元数据将_sync在Couchbase Server中文档的_sync属性下。 The Server SDKs are not currently aware of the revision based system so it will update the field on the document without creating a new revision. Server SDK当前不了解基于修订的系统,因此它将在不创建新修订的情况下更新文档上的字段。

The recommended way to read/write the Sync Gateway data from a Java Web app is to use the Sync Gateway REST API . 从Java Web应用程序读取/写入Sync Gateway数据的推荐方法是使用Sync Gateway REST API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM