我在索引页面中有一个student_names列表。如果我删除学生,它将从Mongo数据库中销毁整个文档。
但是如果我从索引页面删除它,它应该从列表中删除但不想从Mongo数据库中删除它。我不想破坏我的数据库中的任何数据!!!
I know the other ways to achieve
但是我想在mongoid中知道我们是否需要包含一个额外的Mongoid模块来支持它。他们的任何功能都是mongoid !!!
代表:
include Mongoid::Document
include Mongoid::Timestamps
答案 0 :(得分:0)
不,没有。 Mongoid为您提供任何其他数据库的简单CRUD功能。要隐藏数据,您需要将属性设置为hidden
,然后不在视图中显示隐藏的记录。
答案 1 :(得分:0)
答案 2 :(得分:0)
如果计划使用upto mongoid 3进行此操作,可以使用 Mongoid :: Paranoia 。偏执狂对已删除的文档使用 deleted_at 属性,以区别于其余文档,默认情况下在deleted_at:nil上应用范围。
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来说也是如此。