How to remove documents from local database as well as all mobile clients?

Hi All, I’m using Couchbase Mobile iOS so far. I added one channel to my document and my mobile memory increasing day by day. so I decided to remove some documents whatever created 30days before i.e I want to keep only last 30 days of documents, for this I tried purge method in Couchbase lite 1.2 and document expiration in Couchbase lite 1.3 both are same. By using this I’m able to remove the document from only that particular mobile client.Same document still exist in another mobile client. If I sync again complete data to mobile client the purged or expired document is again syncing.
Here my requirement is If the document was created 30 days before it should be removed from all the mobile clients as well as if i sync complete data it won’t sync again and they should be available in sever. is there any way to do this?


Expiration is currently a local property that doesn’t sync. If you want documents to expire after 30 days on all clients, then code the client app to set a 30-day expiration time on all documents as they’re created (or received from the server.) This is pretty easy to do by using a DatabaseChange event/notification listener.

Thank you @Jens, Here is my requirement, Once I removed the existing app from my mobile and install it again from Appstore.Now I’ll sync the data, in this case the expired documents(which are purged or by using expiration property) are syncing again. I don’t want to sync expired or purged documents again when I reinstall the app. Is there any way to do this?

Deleting the mobile app deletes all local state, so when the app is reinstalled it has no knowledge that you had expired those docs. The docs still exist on the server, so they’ll be synced again.

It sounds like you need to change server-side state, if you want this to persist across app deletions. If you expire the docs on the server too, then clients won’t re-pull them.

Thank you @jens, for your quick response. Can you please explain how to do doc expiration on server side?

PUT the document and add an _exp property to the JSON body whose value is either an ISO-8601 JSON date/time string, or a numeric timestamp. The timestamp is interpreted either as a number of seconds [or is it ms? I’m not certain], or as a standard Unix timestamp.

Is it possible to do this from app side coding?

No; as I said, the expiration doesn’t sync. You can do this from a server-side process that’s watching incoming document changes.

@Jens, thanks for the reply. Is it possible to do _exp property of the JSON body, when I create a new document from the client side. So when it goes to the server, it will not affect to others.

If it is only possible in server side. Then shall we use any schedule task to change each and every doc to _exp.

No. The _exp isn’t really part of the document body; it’s just a parameter recognized by the SG REST API in a PUT request.

After I expire the docs on the server,the docs will be deleted,or just marked as expired?let’s say I stored docs in Couchbase Server, After the docs expired,Can I got the docs directly from Couchbase Server by N1QL for example?

I just test and confirm that when the docs expired,the docs will be deleted in couchbase server.
Is there any way to keep docs in Couchbase Server,and don’t sync to Client while the docs “expired”?
And If I want to resync the docs, I can set the “expire” to a new time,the docs will be synced?

Setting the expiration in SG literally just sets the expiration field in Couchbase Server, meaning the docs will be entirely deleted.

If you want something fancier, you’ll have to implement it yourself using channels. For example, have a channel for each month. Then client can decide which channels to pull.