1. How would I write a filter function on server side which accepts params and works on the basis of params.
2. Where do I need to specify that filter function because in case of CouchDB I was using _design documents to write my filter functions. But now at mobile platform I am using CBLite but on the server side it is CouchDB. How will I exactly write filters?
PankaJ Jakhar
There Is No Secret Ingredient. It’s Just You.
--To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/D301F86C-CAB8-41F7-8A8C-E578AC727444%40mooseyard.com.
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/JoJeEJyhBuY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
mDatabaseLocal.setFilter("Filter", new ReplicationFilter() { @Override public boolean filter(SavedRevision savedRevision, Map<String, Object> map) { String property = savedRevision.getProperty("text").toString(); String text = map.get("text").toString(); if(property == text) return true; return false; } }); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("text", "a"); pullReplication.setFilter("filter");
filter(SavedRevision savedRevision, Map<String, Object> map)
{ "docFilter": "function(doc, req) {if(doc.text == req.query.text){return true} else { return false}}"}
Oaky. Thanks for your help.
Here I tried filtered replication. I was getting the result using HTTP query on curl shell but CBLite android does not return document. Here is the description.
I am using this method for filtered replicating a document which has "text" field's value "cblite". Here is the code(You can simply replace ).
private void startSync() {
URL syncUrl;
try {
syncUrl = new URL(SYNC_URL);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Replication pullReplication = mDatabaseLocal
.createPullReplication(syncUrl);
//Temporarily setting filter.
Map<String, Object> map = new HashMap<String, Object>();
map.put("text", "cblite");
pullReplication.setFilterParams(map);
pullReplication.setFilter("docFilter");
pullReplication.setContinuous(true);
Replication pushReplication = mDatabaseLocal
.createPushReplication(syncUrl);
pushReplication.setContinuous(true);
pullReplication.start();
pushReplication.start();
pullReplication.addChangeListener(this);
pushReplication.addChangeListener(this);
}
But nothing is being replicated. If I remove the filter then replication works successfully, replicating all documents.
Also, I have tested my database if the filter is working or not. So running this Curl query, replication was successful.
curl -H 'Content-Type: application/json' -X POST http://localhost:5984/_replicator -d \
'{
"source":"sync_gateway",
"target":"http://localhost:5984/testreplication",
"create_target":true,
"continuous":true,
"filter":"grocery-sync/docFilter",
"query_params":{"text":"cblite"}
}'
and here is the filter
{
"docFilter": "function(doc, req) {if(doc.text == req.query.text){return true} else { return false}}"
}
Note: I am using CouchDB on the Server side.
--To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/731f63be-373d-4aca-b491-441396c8b436%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/0e0a44b5-4499-4ffa-a79e-07d416751c55%40googlegroups.com.