2

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. Then i tried to insert document from JAVA Web application to local server and i succeed to do that. But the problem is that the document inserted by java web application is not syncing with both ios/android mobile applications. My java code to insert document to local server is as follows:

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.

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

Sachin Nikumbh
  • 911
  • 11
  • 11

2 Answers2

0

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.

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

pushpendra chauhan
  • 2,205
  • 3
  • 20
  • 29
0

At the time of this writing, it's not possible to use the Server SDKs on the bucket used by Sync Gateway. 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. Some of that metadata is persisted under the _sync property in the document in Couchbase Server. 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.

The recommended way to read/write the Sync Gateway data from a Java Web app is to use the Sync Gateway REST API.

jamiltz
  • 1,144
  • 8
  • 15