Search code examples
couchdbcouchcocoa

CouchDB delete and recreate a document


I'm trying to avoid revisions building up in my CouchDB, and also so I can use TouchDB's "bulk pull" for replication (it bulk-pulls on all 1st-revs.) Would it be bad practice to just delete a document, and recreate it rather than modifying it, in order for all documents to stay at rev-1?


Solution

  • Deleting a document in CouchDB, will not reset the _rev.

    CouchDB never deletes a document, it simply marks the last revision as deleted. Compaction will delete previous revisions, keeping only the last one. This is needed for replication to work properly. And this is why the deleted revision of a document should not contain any data, but only the _id of the document and the _deleted flag.

    The only method to completely remove any traces of deleted documents, is to copy all documents to a new database. But keep in mind the consequences on replication.