Stop Replication form Couchdb android

#1

Greetings,
I want to display data from the couch database without using replication. I am using IBM cloudant and replication leads to a spike in my account usage, So how do I Sync with database, without replicating all the time?
Here is the sync code:

 private void startSync() {
        URL syncUrl;
        try {
            syncUrl = new URL(SYNC_URL);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        Application application = (Application) Betslip.this.getApplication();

        Replication pullReplication = application.getDatabase6().createPullReplication(syncUrl);
        pullReplication.setContinuous(true);

        Replication pushReplication = application.getDatabase6().createPushReplication(syncUrl);
        pushReplication.setContinuous(true);

        pullReplication.start();
        pushReplication.start();
        pullReplication.addChangeListener(new Replication.ChangeListener() {
            @Override
            public void changed(Replication.ChangeEvent event) {
                Replication replication = event.getSource();
                com.couchbase.lite.util.Log.d(TAGz, "Replication : " + replication + " changed.");
                if (!replication.isRunning()) {
                    String msg = String.format("Replicator %s not running", replication);
                    com.couchbase.lite.util.Log.d(TAGz, msg);
                } else {
                    int processed = replication.getCompletedChangesCount();
                    int total = replication.getChangesCount();
                    String msg = String.format("Replicator processed %d / %d", processed, total);
                    com.couchbase.lite.util.Log.d(TAGz, msg);
                }

                if (event.getError() != null) {
                    showError("No internet connection please put it on", event.getError());
                }

            }
        });
        pushReplication.addChangeListener(new Replication.ChangeListener() {
            @Override
            public void changed(Replication.ChangeEvent event) {
                Replication replication = event.getSource();
                com.couchbase.lite.util.Log.d(TAGz, "Replication : " + replication + " changed.");
                if (!replication.isRunning()) {
                    String msg = String.format("Replicator %s not running", replication);
                    com.couchbase.lite.util.Log.d(TAGz, msg);
                } else {
                    int processed = replication.getCompletedChangesCount();
                    int total = replication.getChangesCount();
                    String msg = String.format("Replicator processed %d / %d", processed, total);
                    com.couchbase.lite.util.Log.d(TAGz, msg);
                }

                if (event.getError() != null) {
                    showError("No internet connection", event.getError());
                }
            }
        });

    }
#2

Hello @mikekara,

If you don’t want to use the replication method of retrieving the data, another way is using the REST APIs to GET the document or POST to the database.

Curious how is Couchbase fitting within your Cloudant architecture?

#3

You’ll want to use a one-off replication rather than a continuous replication. This will give you full control on when replication happens.

#4

Consider using a filtered replication from Cloudant, so you can pull down just the important documents. (Filtered replications are mostly configured on the server side; read the Cloudant or CouchDB docs for how to do it.)

#5

See
http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/replication/index.html#types