Is there a filtered push replication example anywhere?

.net

#1

I’m looking for an example of how to use the filtered push replication. I see a filter property and filter params on the replication, but no obvious way to use this functionality.

Are there examples for how to do a filtered push?


#2

Yes it is available in the documentation but again it depends on the couchbase lite version you are using.

for 1.4.1 you can refer to https://developer.couchbase.com/documentation/mobile/1.4/guides/couchbase-lite/native-api/replication/index.html#filtered-push-replications

Following is the code sample there in android:-
// Define a filter that matches only docs with a given “owner” property.
// The value to match is given as a parameter named “name”:
db.setFilter(“byOwner”, new ReplicationFilter() {
@Override
public boolean filter(SavedRevision revision, Map<String, Object> params) {
String nameParam = (String) params.get(“name”);
return nameParam != null && nameParam.equals(revision.getProperty(“owner”));
}
});
//
// Set up a filtered push replication using the above filter block,
// that will push only docs whose “owner” property equals “Waldo”:
Replication push = db.createPushReplication(url);
push.setFilter(“byOwner”);
Map<String, Object> params = new HashMap<String, Object>();
params.put(“name”, “Waldo”);
push.setFilterParams(params);

I am not sure if we have enough documentation for 2.0 or it is implemented for 2.0 (fyi @priya.rajagopal, @jens @househippo)

I tried but for 2.0 its not in config and not a property of database.

Please alway make sure to provide the version you are using.


#3

Thank you, that is what I was looking for.

We’re using 1.4.1.2 at the moment, but it would be interesting to know if this feature is present in 2.0.


#4

filterParams on push replication is not yet supported in 2.0. It’s being tracked for future releases. You can filter on documentIds though.