CouchDB delete and recreate a document

1.1k Views Asked by At

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?

2

There are 2 best solutions below

6
Marcello Nuccio On BEST ANSWER

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.

0
lecstor On

well I want to say that your proposal makes me feel dirty, but that wouldn't be an SO answer so..

You mention TouchDB and bulk pull so you have a mobile app with data which can be modified externally and I assume wants to be able to modify it's own data. So the biggest issue I can think of would be update conflict resolution. ie. how do you handle changes to the document on both the client and the server while the client is offline. I think you'll start having to do a lot of the synchronisation work that couch is meant to handle for you..