蒙古文件草案 [英] Draft documents in Mongo

查看:170
本文介绍了蒙古文件草案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Mongo集合和一个Web应用程序来查看Internet中的集合。当我编辑集合(即添加,删除和更新文档)时,我的更改可以立即在互联网上使用。



现在我将喜欢将所有更改保存为草稿,而当我想使其可用时,我将显式地发布草案



这个简单的实现是添加一个新的草稿集合。我只编辑这个草稿集合,当我按发布按钮时,草稿集合将被复制到原始集合。



到目前为止这么好,但这个解决方案是不可扩展的,因为复制的时间是收集大小的函数。你会建议另一个解决方案吗?

解决方案

在每个文档中有一个字段,如果文档是草稿,则是一个草稿。如下:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆