On the iOS API, what is the best way to remove all local documents if the user logs out, so that the next user to log in doesn’t have access to any of the documents from the user before?
Or to a lesser extent, how can I purge all documents from a channel locally once I remove the user’s access to that channel?
You can use the purge method on a document to completely remove it from the database (removing the tombstone as well).
Or you can bulk delete all tombstone revisions with the compact method on the database.
In your case, I would consider having one database per user. ToDoLite-iOS has a databaseForUser method that returns a database for the user logged in, the user name/identifier is used to create a unique db name.
Delete, purge, and compact all seem to propagate back to the server, and I am looking for a better way to manage local documents specifically. Changing databases is a good idea, and one that I have tried before, but even if I change the name of the database either 1) the documents stay the same or 2) the pull replicator doesn’t take the new user channels into account, because the documents that correspond to the channels of the old users are still present in the database.
I am looking for a way to:
Log out
Remove all local documents from device
Log in
Re-pull documents that that user has access to
Unless there is a better way to purge documents from the local device from which that user should not have access to.
**Update: restarting the app seems to remove the documents that the new user does not have access to, but how can I simulate this without restarting the app?
If you create a new database per user and use it through out the application there shouldn’t be a problem with regards to documents belonging to other users.
Re-creating the push/pull replicators on the new database and passing the credentials of the logged in user will create a new Sync Gateway session cookie for that user and only the documents part of the user channels will be replicated. Which version of Couchbase Lite are you using?
You can just call delete on the database object to delete all the content of the database.