Exclude some documents from syncing

Hi everyone.

I wanted to know if it’s possible to exclude some document from being pushed to the sync gateway. I know I can set a channel on the pull replication, but I want it on the push side. I have this use case: A user is working on some stuff that can be edited. There are many fields that can be edited. When the user is “working” on this stuff, I need to persist the job on the device to let him begun from where he has left. From specs anyway, this has not to be synced. It has to be synced only when the job is done! In this case I was thinking to create another DB (not couchbase framework) on the device, persist objects and so on… But if I want to work only with a Couchbase framework, is there any way to tell to couchbase (the pushReplication probably?) to not sync that document? So that when the job is done, I change a boolean, update the document, and then it is synced? This is the first and easiest thing to do that came up in my mind.

Thank you!

Ok guys, I was able to do this. For anyone this is the code:

First, set the filter on the database side:

database.setFilter("sync_gateway/bysyncflag", new ReplicationFilter() {
        @Override
        public boolean filter(SavedRevision savedRevision, Map<String, Object> map) {
            //Log.e(TAG,"Filter");
            if (savedRevision.getProperties().get("excludeFromSync") != null) {
                Log.e(TAG,"This document has something");
                boolean excludeFromSync = (Boolean) savedRevision.getProperties().get("excludeFromSync");
                Log.e(TAG,"This document has excludeFromSync to: " + excludeFromSync);
                return !excludeFromSync;
            }
            return true;
        }
    });

And then, set the filter on the replication (Pull or push, you choose. I needed for the push one):

    Replication pushReplication = database.createPushReplication(syncUrl);
    pushReplication.setContinuous(true);
    pushReplication.setFilter("sync_gateway/bysyncflag");

Note: The filter name must be the same

Thanks for posting your solution!