Filter documents by Date

89 views
Skip to first unread message

Victor Fernandez

unread,
Apr 20, 2015, 12:40:06 PM4/20/15
to mobile-c...@googlegroups.com
Hi
Does anyone know the best way to filter documents in the syncronization process between Couchbase Lite and Sync Gateway using the date as a discriminative element?
For example, today is April 20. I want to syncronize all the documents with dates April 17,18,19 and 20. I want to discard documents with previous dates.
I am working with Objective-c and CouchbaseLite.

Thanks and regards!

Jens Alfke

unread,
Apr 20, 2015, 12:57:50 PM4/20/15
to mobile-c...@googlegroups.com
On Apr 20, 2015, at 9:40 AM, Victor Fernandez <vfern...@txmglobal.com> wrote:

Does anyone know the best way to filter documents in the syncronization process between Couchbase Lite and Sync Gateway using the date as a discriminative element?
For example, today is April 20. I want to syncronize all the documents with dates April 17,18,19 and 20.

Are you talking about pull or push (or both?) The answers are different…

I want to discard documents with previous dates.

You’ll need to find the documents, probably using a view query, and then call -purgeDocument on each one.

—Jens

Victor Fernandez

unread,
Apr 20, 2015, 1:09:19 PM4/20/15
to mobile-c...@googlegroups.com
Sorry for not being clear, I'm talking about pull replication.
I understand I can do a purgeDocument on the mobile app to discard any unwanted old document, but what I want to do is to avoid the sync gateway process to download data older than, let's say 7 days. Is it possible to set a filter on sync gateway configuration to do this? If so, how?

Jens Alfke

unread,
Apr 20, 2015, 2:20:43 PM4/20/15
to mobile-c...@googlegroups.com

On Apr 20, 2015, at 10:09 AM, Victor Fernandez <vfern...@txmglobal.com> wrote:

I understand I can do a purgeDocument on the mobile app to discard any unwanted old document, but what I want to do is to avoid the sync gateway process to download data older than, let's say 7 days. Is it possible to set a filter on sync gateway configuration to do this? If so, how?

You could run a server-side process to purge documents older than 7 days, if you don’t want to keep them on the server.

If you want them on the server but just don’t want your client to pull them, it’s a little tricky since you can’t assign docs to channels by relative dates (a doc only gets assigned to channels when it's updated, when its age is by definition zero.) The advice I give is to define per-week channel names (like “2015-01” for the first week in 2015) and have the sync function assign a doc to one such channel based on a timestamp property in it. The client then comes up with the channel name for the current week and explicitly pulls that channel.

—Jens
Reply all
Reply to author
Forward
0 new messages