Delete a document with attachments

a very basic question, when I delete a document, does it automatically delete its attachments?

What if I query the deleted document? Is the attachment still there in [CBLRevision attachmentNames]?

Deleting a document simply replaces its body with {"_deleted":true}, i.e. a flag indicating deletion and no other properties. The lack of an _attachments property means it has no more attachments.

The attachment files themselves will stay around until you run a compaction though FYI.

What if I call purgeDocument? Is it going to remove attachments? Thanks.

If you purge the document, it’s gone.

Are you talking about accessing the attachments through an API, or are you concerned with the actual storage taken up on disk?

I am concerning the space taken by the database. According to the document, if a document TTL expires, it will be purged from DB, so the attachments will be deleted as well. Right?

But the document also says "Purging documents does not remove the space used by them on disk. To reclaim disk space, run a database compact "

Does couchbase-lite automatically do compaction?

The short answer: The disk space occupied by attachments is only cleaned up when the database is compacted. Compaction is manual; you have to call Database.compact.

(Internally, the database file itself contains only references to attachments. The attachments themselves are stored as individual files in a subdirectory. Since multiple documents or multiple revisions can refer to the same attachment, the cleanup has to be done like garbage collection, where the database is scanned to find all of the attachment references, and then the attachment files that aren’t referenced are deleted.)