Android PushReplication filtering deleted documents

Hi, I am trying to build a mobile application wich needs to sync data to a couhbase server, but only new data or updated data; and need to filter deleted documents so the server keep the document even when at the mobile the user delete the document; I can not use thombstone or something like that, just need the document at the server as it was on revision 1.

This is a piece of code where I am trying to achieve this:

pushReplication = database.createPushReplication(syncUrl);
database.setFilter(“unDeleted”, new ReplicationFilter() {
@Override
public boolean filter(SavedRevision savedRevision, Map<String, Object> map) {
return !savedRevision.isDeletion();
}
});
pushReplication.setContinuous(false);
pushReplication.setFilter(“unDeleted”);

Can someone please guide me on this ? This will be a deal breaker for my testing project.

I’ll appreciate yout help.

That looks reasonable. What’s going wrong?

It is very weird, sometimes when I delete a document and star a replication the deletion does not replicate (wich is the desire behavior), but sometimes the delete document replicates and that is not acceptable for my application, I don’t know I am kind of frustrated. The general idea is a one way push replication no pull; it suppouse to be easy and right now I am on the egde of declare forfeit opn this, hehehe

Hi anibalec,

It seems your codes are correct. Following is CBL iOS unit test codes to apply filter. Please refer this as a reference implementation.

Also you can refer the filtered replication section of Replicator in CBL Guide. Some reason, Android/Java sample is missing. But Obj-C, Swift and C# samples are available.
http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/replication/index.html#filters

If this is bug, could you please file the ticket on https://github.com/couchbase/couchbase-lite-java-core/issues ?

Thanks,
Hideki

It’s working for me. Here’s a sample project using filtered push replication.

1 Like

@jamiltz Thank you very much for your sample!