Michael Pickett Michael Pickett - 1 year ago 52
Javascript Question

Apache CouchDB Filtered replication with javafx

I am using CouchBaseLite on javafx with Apache CouchDB, specifically the FUTON interface. I currently have a filter function working,

"function(docu, req) {
if(docu.orgId == req.query.orgId && docu.doc == req.query.doc)
return true;
return false;

I am currently setting the filters by doing,

Map<String, Object> params = new HashMap<>();
Map<String, Object> params2 = new HashMap<>();
Map<String, Object> params3 = new HashMap<>();
Map<String, Object> params4 = new HashMap<>();

params.put("orgId", 0);
params.put("doc", "doc1");
params2.put("orgId", 0);
params2.put("doc", "doc2");
params3.put("orgId", 0);
params3.put("doc", "doc3");
params4.put("orgId", 0);
params4.put("doc", "doc4");



Where doc# are doc types. and pullDoc# are Pull Replications.

I was wondering if there was a way to leverage using an ArrayList or List of Strings as a parameter as opposed having 4 separate pull replications for each doc type.

So to recap my questions are

  1. Is there a way to leverage using an ArrayList or List of Strings as a parameter?

  2. What would the javascript of my filter function look like?

  3. What would my javafx code look like?

Thank you.

Answer Source

As you described it, I updated your code so you can use a filter function with many doc value.

Filter function

function(docu, req) {
    if (docu.orgId == req.query.orgId && docu.doc != null && req.query.docs.indexOf(docu.doc) > -1)
        return true;
        return false;

Java code for params

    //We create our param associated array
    Map<String, Object> params = new HashMap<>();
    //Here can pu the orgId. This is a single value
    params.put("orgId", 0); 

    //Here we send an array of doc that we want to get.
    params.put("docs", new String[]{"doc1", "doc2", "doc3", "doc4"});

If you have any other questions, feel free to ask.