蒙古文件草案 [英] Draft documents in Mongo
问题描述
现在我将喜欢将所有更改保存为草稿,而当我想使其可用时,我将显式地发布草案。
这个简单的实现是添加一个新的草稿集合。我只编辑这个草稿集合,当我按发布按钮时,草稿集合将被复制到原始集合。
到目前为止这么好,但这个解决方案是不可扩展的,因为复制的时间是收集大小的函数。你会建议另一个解决方案吗?
在每个文档中有一个字段,如果文档是草稿,则是一个草稿。如下:
title:FooBar blah blah,
draft:true
当点击按钮发布帖子时,您只需要更新单个文档 - 该帖子的文档将草稿更改为false或 $ unset
它。您选择要显示哪些文档的查询必须检查草稿:{$ ne:true}
- 请注意,这将匹配两个文件,草稿设置为false和文档根本没有字段草稿
。这允许您单独离开当前文档,并且不需要更新它们以具有此字段。
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 ?
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.
这篇关于蒙古文件草案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!