Is DELETE enough? (Couchbase Lite Deletion Of Document)

Hopefully this is a simple question, but does the .Delete(document) method get rid of all previous meta data related to that couchbase document? In other words, would the size of the couchbase lite slowly creep up if you run through and delete 1000s of documents with the .Delete method? I’ve seen in other threads, if you do wish to delete all documents with for example with a specific _type parameter; you have to go get all the documentids involved and then individually Delete each document.

For example, this individual document delete code… (C#, Xamarin Forms, .NET Standard project)

        var document = _database.GetDocument(documentId);
       _database?.Delete(document);

I assume, if you iterate over it many times over, it will fully DELETE the document and any meta data associated with it (thereby not allowing the database size to creep up over long periods of time).

Short answer: No. If you want to nuke a document and all its metadata, call Purge instead.

Longer answer: Deletion is replicated: if you delete a doc locally, that deletion will propagate to the server and then to all other devices that sync with that database. For this reason, deletion has to preserve document metadata so there’s something to sync. In fact, deleting a document is actually identical to saving a document with a body that’s empty except for a single property "_deleted":true.

Purging a document is more extreme: it actually deletes the document and all its metadata. There’s nothing left to indicate the document ever existed. For this reason, though, it doesn’t replicate. Think of it as just removing your local cache of the document. In fact if the document is later updated on the server, your database will see it as a new document and pull it again.

1 Like