Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm currently working on a wiki-esque application using CouchDB and am trying to implement a document versioning scheme. The way I see it there are two ways of doing this:

  1. Store each version as a separate document
  2. Store older versions as attachments to a single document.

Right now, I've got a form of #1 working. When a user edits a document and saves it, the back-end first copies the previous revision to a new document and then saves the new version. Each document has a 'history' array that contains data on each version (the document _id of the old version, a timestamp, the editor, etc.).

Since this history array could get pretty lengthy for a frequently updated document, I have a view that fetches a document sans history during a normal read (and another view for fetching the history).

My question is this: I feel uneasy about my current approach and have been thinking about changing to the 'attachment' method. But I'm not sure. I'm hoping someone who knows CouchDB better than I (I've only been at this for a couple weeks -- and this is my first project using CouchDB... and NoSQL) can tell me what the pros and cons are of each approach. Or is there perhaps some other versioning scheme that I'm overlooking?

share|improve this question

migrated from programmers.stackexchange.com Oct 11 at 7:19

This question came from our site for professional programmers interested in conceptual questions about software development.

1  
While I can't speak to the performance impact at all, the system you are using is "spiritually" in line with CouchDB. Storing previous versions as a response hierarchy is idiomatic, as it is in the "spiritual ancestor" of CouchDB, the Lotus Notes document database (NSF) (Damien Katz worked deeply on the one before developing the other, keeping and improving the best of it while tossing the cruft and backward/bugward compatibility requirements, so many of the more basic structural questions will have answers in Notes.) –  Stan Rogers Oct 4 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.