Deleting documents locally while keeping them in server

#1

Is there any way or best practices to delete documents locally while keeping them in the server?

Our users (Native Android and Phonegap (android/ios) app) will be creating about 300 documents per day plus about 300 edition so the local database will grow quickly. I’m thinking on a scenario where documents older than 3 months are deleted on the local database but they are still on server (I don’t want to lose that data). In case the user needs to look at old data, I will request them on demand. I’m assuming performances slow down when the amount of documents grow.

The first question is: Is this scenario viable? how?

I’m aware performance depends on hardware but is there any information about the recommended amount of local documents to have a great user experience and don’t build a slow app?

Thanks!

How delete a document on *all* mobiles but not on server
#2

You can delete and purge them in the app and they will remain on the server. But the next time you do a pull replication, they will get synced down again. So you would also need to remove the user access from that channel.

This could perhaps work:

  • In the push replication make sure all the docs were pushed to Sync Gateway by checking the status
  • Toggle a property on the user’s Profile document for example to remove the user from the channel containing the docs you want to delete
  • Check that the update to the Profile was pushed by checking the replication status again
  • Delete and purge the documents

This way, the docs will be on the server and not local.

There could be a boolean property on the user’s Profile document for example. When the user toggles a switch on the UI, update that property. In the sync function, if the property is true/false, grant/remove the user access to the archive channel.

PS: Fyi, you can also specify a channel name in the pull replication.

James

#3

One minor correction: deleting and purging are two different operations.
To do a purge, you simply purge, no reason to delete it first (and in fact,
that will have unwanted side effects for this use case)

http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/document/index.html#purging-a-document

#4

That’s not quite true. They’ll only get downloaded again if the pull replicator has to start over and do a ‘slow sync’, which rarely happens. But yes, you can’t rely on the document staying gone forever, if the client still has access to the server-side version.