2014-03-19 119 views
0

我有索引页中的student_names列表。如果我删除一个学生,它会从Mongo数据库中销毁整个文档。Mongoid - 删除模块

但是,如果我从索引页面中删除它,它应该从列表中删除,但不想从Mongo数据库中删除它。我不想从我的数据库中销毁任何数据!

I know the other ways to achieve但我想知道在mongoid中我们需要包含一个额外的Mongoid模块来支持它。他们的任何功能都可用于mongoid!

为前:

include Mongoid::Document 
include Mongoid::Timestamps 
+0

真不明白你的要求。但是,你是否想从你的客户端视图中删除一些东西,而没有发送到你的服务器?如果情况确实如此,没有看到这是一个多边形问题。这只是JavaScript。可能重新短语/重新考虑你的问题。 –

回答

0

没有没有。 Mongoid为您提供任何其他数据库的简单CRUD功能。要隐藏数据,您需要将属性设置为hidden,然后不会在视图上显示隐藏的记录。

0

是有

include Mongoid::Paranoia 

但问题它不是要去长时间的支持。检查mongoid docs

所以,如果你打算升级到mongoid 4不依赖于此。

0

如果打算使用upto mongoid 3来做到这一点,您可以使用Mongoid :: Paranoia。偏执狂使用deleted_at属性为已删除的文档区分它们,并将范围应用于deleted_at:默认情况下为零。

include Mongoid::Paranoia 
document.delete # Deleting it from index but keep it in DB 
document.delete! # Delete it from collection permanently 
document.destroy # Sets the deleted_at field, firing callbacks. 
document.destroy! # Permanently deletes the document, firing callbacks. 
document.restore # Brings the "deleted" document back to life. 
collection_class.deleted # To show all deleted documents (marked as deleted) 

如果您计划到一起mongoid 4移动,你可以给一个镜头在https://github.com/simi/mongoid-paranoia,这也做着同样的事情mongoid 4.