Question

Suppose I have a Mongo collection and a web application to view the collection in the Internet. When I edit the collection (i.e. add, delete, and update the documents) my changes are instantly available in the Internet.

Now I would like to save all my changes as a draft and when I want to make it available I will publish the draft explicitly.

The trivial implementation is to add a new draft collection. I edit only this draft collection and when I press a publish button the draft collection is copied to the original collection.

So far so good, but this solution is not scalable since the time of the copy is a function of the collection size. Would you suggest another solution ?

Was it helpful?

Solution

Have a field in each document that's a draft that's set if the document is a draft. Something like:

title:"FooBar blah blah",
draft:true

When the button is clicked to publish the post you only need to update a single document - that post's document to either change draft to false or $unset it. Your queries which choose which documents to display must be checking for draft:{$ne:true} - note that this will match both documents which have draft set to false and documents which don't have the field draft at all. This allows you to leave the current documents alone and not need to update them all to have this field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top