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 Answers
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..

- 5,619
- 21
- 27
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.

- 3,901
- 2
- 28
- 28
-
Thanks Marcello. I suppose for this to succeed I'd need to pretty much create a custom identifier, and disregard _id... then I could just count each doc as brand-new... – ewindsor May 28 '12 at 21:13
-
I'm not sure to understand what you are trying to achieve. I use a custom _id when I reference the doc by its id, or, in other words, when the application uses the id to retrieve the data stored in the document. It also depends on how do you want to do conflicts resolution... but that's too much for a comment. – Marcello Nuccio May 29 '12 at 07:09
-
Well, I mean actually creating a new field to use as the ID for other docs... and deleting / recreating each time. Main goal here is to have every doc be 1st-rev. I have a feeling though I might be bending CouchDB a way it's not meant to be. – ewindsor May 29 '12 at 21:43
-
I don't get why you care about the value in _rev. The only sane use of _rev is to check if it's equal to the value of _rev of docs with the same _id. What's the problem that are you trying to solve? – Marcello Nuccio May 30 '12 at 06:21
-
Bulk document downloading with TouchDB. Touch only grabs in bulk 1st Rev's -- anything else, it gets 'em one-by-one. With > 100 docs, Cloudant has problems with it, and it would be slow for 3G client. So if I can have everything 1st-rev... I'd be able to utilize CouchDB's replication from Cloudant <-> iPhone, and do it efficiently (in bulk.) – ewindsor May 30 '12 at 06:30
-
Sorry, I've never used TouchDB, so I can't answer. With CouchDB, I've never had this problem. – Marcello Nuccio May 30 '12 at 07:06