Search code examples
androidcloudant

Cloudant sync android filtered pull


my database has a lot of documents, and each document has a field called doc_type, so i can filter it, but android is giving a error while trying to filter:

Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("doc_type", "doc_company");
        PullFilter filter = new PullFilter("company/list", parameters);
        Replicator replicator = ReplicatorBuilder.pull()
                .from(uri).to(ds)
                .filter(filter)
                .build();

the error:

       CouchException: error: Unknown error, reason: Unknown reason, statusCode: 404, msg: Object Not Found, cause: java.io.FileNotFoundException: https://(my_user_here).cloudant.com:443/db_404040/_changes?style=all_docs&feed=normal&filter=company/filter&doc_type=doc_company&limit=1000
 at com.cloudant.sync.internal.mazha.CouchClient$ExecuteResult.<init>(CouchClient.java:112)
 at com.cloudant.sync.internal.mazha.CouchClient$ExecuteResult.<init>(CouchClient.java:85)
 at com.cloudant.sync.internal.mazha.CouchClient.execute(CouchClient.java:188)
 at com.cloudant.sync.internal.mazha.CouchClient.access$100(CouchClient.java:54)
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:245)
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:242)
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:209)
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:242)
 at com.cloudant.sync.internal.mazha.CouchClient.executeToJsonObjectWithRetry(CouchClient.java:227)
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:301)
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:295)
 at com.cloudant.sync.internal.replication.CouchClientWrapper.changes(CouchClientWrapper.java:125)
 at com.cloudant.sync.internal.replication.PullStrategy.nextBatch(PullStrategy.java:451)
 at com.cloudant.sync.internal.replication.PullStrategy.replicate(PullStrategy.java:235)
 at com.cloudant.sync.internal.replication.PullStrategy.run(PullStrategy.java:177)
 at java.lang.Thread.run(Thread.java:761)
                Caused by: java.io.FileNotFoundException: https://(my_user_here).cloudant.com:443/db_404040/_changes?style=all_docs&feed=normal&filter=company/filter&doc_type=doc_company&limit=1000
 at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
 at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
 at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
 at com.cloudant.http.HttpConnection.responseAsInputStream(HttpConnection.java:420)
 at com.cloudant.sync.internal.mazha.CouchClient.execute(CouchClient.java:171)
 at com.cloudant.sync.internal.mazha.CouchClient.access$100(CouchClient.java:54) 
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:245) 
 at com.cloudant.sync.internal.mazha.CouchClient$1.call(CouchClient.java:242) 
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:209) 
 at com.cloudant.sync.internal.mazha.CouchClient.executeToInputStreamWithRetry(CouchClient.java:242) 
 at com.cloudant.sync.internal.mazha.CouchClient.executeToJsonObjectWithRetry(CouchClient.java:227) 
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:301) 
 at com.cloudant.sync.internal.mazha.CouchClient.changes(CouchClient.java:295) 
 at com.cloudant.sync.internal.replication.CouchClientWrapper.changes(CouchClientWrapper.java:125) 
 at com.cloudant.sync.internal.replication.PullStrategy.nextBatch(PullStrategy.java:451) 
 at com.cloudant.sync.internal.replication.PullStrategy.replicate(PullStrategy.java:235) 
 at com.cloudant.sync.internal.replication.PullStrategy.run(PullStrategy.java:177) 
 at java.lang.Thread.run(Thread.java:761) 

i have the document with filter function:

{
  "_id": "_design/company",
  "_rev": "15-49d2081b2e3c35ae833617fd2356e6d3",
  "views": {
    "list": {
      "map": "function (doc) {\n  emit(doc);\n}"
    },
    "filter": {
      "map": "function (doc, req) {\n  emit(doc._id, 1);\n}"
    }
  },
  "language": "javascript"
}

when i access

https://(my_user_here).cloudant.com:443/db_404040/_changes?style=all_docs&feed=normal&filter=company/filter&doc_type=doc_company&limit=1000

it give me this message:

{"error":"not_found","reason":"missing json key: filters"}

whats wrong? i did exactly what documentation says https://github.com/cloudant/sync-android/blob/master/doc/replication.md (at the end)


Solution

  • i found -> groups.google.com/forum/#!topic/mobile-couchbase/tw5462qMFeM

    i removed the _replicator document from cloudant database(online) and it started to work