I did not manage to pull replication data from CouchDB.
I am using CouchDB for my document storage.
CouchDB Version: Apache CouchDB 1.6.1
Couchbase Lite: Couchbase Lite 1.4.0
Below are my sample data:
{
"_id": "ab33deeb074523e3c63c216b8c2952a8",
"_rev": "6-e196bfb6aca85492e4f96f3af6fd1ee2",
"type": "employee",
"employee": {
"employeeId": "1",
"employeeName": "Test"
}
}
In CouchDB, I have created my own design filter:
{
"_id": "_design/employee",
"_rev": "35-00f59706402452291d30c3fb6e9a5356",
"filters": {
"byEmployeeId": "function(doc, req) {
if(doc.type != 'employee') {
return false;
}
if(doc.employee.employeeId == req.query.employeeId) {
return true;
} else {
return false;
}
}"
}
}
On the other hand, I am using Couchbase Lite as my Android Mobile project to replication pull the employee data:
Replication pull = this.getCouchbaseUtility().getDatabase().createPullReplication(
new URL("http://localhost:5984/testdb")
);
pull.setAuthenticator(authenticator);
pull.setContinuous(false);
pull.setFilter("employee/byEmployeeId");
Map<String, Object> params = new HashMap<>();
params.put("employeeId", "1");
pull.setFilterParams(params);
pull.addChangeListener(new Replication.ChangeListener() {
@Override
public void changed(Replication.ChangeEvent event) {
System.out.println(event.getStatus());
}
});
pull.stop();
pull.start();
The App runs with no error, but it did not successfully replicate the data to the mobile Couchbase storage.
If I change the design filter to return always true, App can replicate the employee document from CouchDB. Could it be req.query.employeeId not compatible with Couchbase and CouchDB?
May I know any part that I did wrong?