I am using CouchBaseLite on javafx with Apache CouchDB, specifically the FUTON interface. I currently have a filter function working,
{"orgId":
"function(docu, req) {
if(docu.orgId == req.query.orgId && docu.doc == req.query.doc)
return true;
else
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");
pullDoc1.setFilterParams(params);
pullDoc2.setFilterParams(params2);
pullDoc3.setFilterParams(params3);
pullDoc4.setFilterParams(params4);
pullDoc1.start();
pullDoc2.start();
pullDoc3.start();
pullDoc4.start();
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
Thank you.
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;
else
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.