Android - Couchbase lite - pull with filter - Replication.setFilter

I am working on an android messagerie application, messages are stored in the CouchDB (Apache) database on the Internet. How can I click filter messages on my Android devices?

Android Snippet:

Replication pull = new Replication(messageDB, messageUrl, Replication.Direction.PULL);

//filter
pull.setFilter("message/by_username");
HashMap<String, Object> filterParams = new HashMap<>();
filterParams.put("username", usr);
pull.setFilterParams(filterParams);

pull.setContinuous(false); //oneshot
pull.start();

Apache Design Document:

{
  "_id": "_design/message",
  "views": {
    "by_username": {
      "map": "function (doc) {\n  emit([doc.username]);\n  \n}"
    }
  },
  "filters": {
    "by_username": "function(doc, req){ if(!doc.username) return false; if(req.query.username && req.query.username != doc.username){return false} else {return true}}"
  },
  "language": "javascript"
}

With the block filter, synchronization never stops, but the database is always empty (I did not find any document after 3 minutes).

Without a block filter, all messages are downloaded in just a few seconds. Thank.

+4
source share
1 answer

Source: https://developer.couchbase.com/documentation/mobile/current/guides/couchbase-lite/native-api/replication/index.html#filtered-pull-from-couchdb-pouchdb-or-cloudant

Filtered Click of CouchDB, PouchDB or Cloudant

Couchbase Lite 1.2, pull Couchbase . POST/{db}/_ (. # 1139).

0

Source: https://habr.com/ru/post/1689053/


All Articles