How to purge all documents of a given channel w/o tombstone?

How may I purge all documents from a given channel in couchbase server without getting a tombstone revision synced to the clients?

I’d like to implement a client based backup/restore procedure on the iOS device itself:

  1. Create document A on device
  2. Document A gets synced to the server
  3. Create backup of local *.cblite and * attachments files (basically zip them up and store in different directory)
  4. Create document B on device
  5. Document B gets synced to the server
  6. Restore previously done backup locally
    6.1 Purge all documents of a given channel from server, without creating tombstone revision
    6.2 Delete current *.cblite file and * attachments folder
    6.3 Move the previously created zip file contents to the *.cblite and * attachments places
  7. Start client push replication (all local documents are getting pushed to server)
  8. Start client pull replication (everything’s running as normal again now)

I’m failing in achieving 6.1, how would you do this?

Hi, purging documents should do the trick. Can you show us how you do it?

Hi @ldoguin

I’ve figured out how to delete the server sided documents directly from the couchbase database, without the sync gateway - but it seems there is some caching issue left:

I’m using the cfCouchbase SDK (which is basically just a wrapper for the Java SDK - details here: to delete the questioned documents directly from the database using the delete method: - this delete method calls the com.couchbase.client.CouchbaseClient:delete() method of the underlying Java SDK.

But as soon as I start the pull replication on the client AFTER I’ve deleted the docs from the server database, they are pulled again - nevertheless they should have been removed :frowning:

I assume some sort of caching going on here - any ideas?

MVCC is not designed to go “back in time” which is why tombstone revisions are created in the first place. Also you cannot modify the backing server to Sync Gateway as that will cause things to break. The big problem I see with your approach is this:

You cannot simply purge things at will from a database with no consequences. You must make sure that all the clients are informed of this change first. Say clients A and B have document 1, and you purge it from the remote database and delete the local database on client A. Client B will still have document 1, and will push it during its next push session since the remote database will report not having it. The remote database does not belong to just one client.

Furthermore, Sync Gateway’s purge endpoint is still not implemented

A workaround could involve removing the documents you do not want anymore from the channel and deleting them. After that a compact operation should remove all the old revisions except for the small tombstone, and since the document is no longer in the channel, pulling should not pull it at all.

@borrrden Is there documentation on how to perform a compact operation? Is this available via the Sync Gateway Admin REST API?