kailash yogeshwar kailash yogeshwar - 21 days ago 9
Node.js Question

How to store separate versions of document for a blog using mongodb with nodejs?

I am creating a blog site but i would like to add the feature to have history for a blog what changes are been done in previous version and latest version. Creating a separate history collection will be one approach but what about the document do i need to just copy the document of old revision in history collection or the just the json diff . If we just store the diff of field what will be the base object to construct the upto date document till that revision if we wish to query document with specific revision suppose (__version: 15) and current version will be somewhere 25.

Answer

I'd go with your first option, using a history collection, since it would be easier to fetch an entire document than keeping lot of diffs and then having to sync them all together. Also, having a different collectiont would be a faster solution, since you wouldn't need to fetch for different versions, assemble them and display it.

But on the other side, if you just want to show minor changes, like on facebook when you edit a comment, I think the diff approach would be the best option, altough you'd have to keep references on where and what has changed

Comments