Purge deleted documents

Is there a way to get all deleted documents and remove all those documents out of the database? I don’t have access to the document id, so I need to be able to query all documents that are deleted (tombstoned) and purge those out of the database.

Do an all-docs query with mode kCBLIncludeDeleted to get the IDs of all deleted documents.

Thanks, I will give that a try.

Also, is it recommended to compact the database after a purging documents? Is it recommended to regularly compact the database to improve size and performance or is that unnecessary?

I’ve noticed that it takes a quite a bit of time to compact the database on the server (anywhere between 20-30 seconds before it completely compacts). Does it take the same amount of time locally on a mobile app to completely compact?

SQLite-based databases should be compacted regularly. Unfortunately this is synchronous (other threads can’t access the SQLite database while one thread is modifying it.) The amount of time depends a lot on the size of the database, the number of changes since the last compaction, and the device’s filesystem performance.

ForestDB-based databases auto-compact. It happens in a background thread and doesn’t interrupt access to the database, so you don’t have to worry about it at all.