一段时间后删除monogid中的文档

问题描述:

我正在使用Mongoid开发Rails应用程序.这是模型(集合)之一:

I am working on rails app with mongoid. This is one of model(collection):

class Document
 include Mongoid::Document
 include Mongoid::Timestamps
 include Mongoid::Paperclip

 field :time, type: Time
 field :radius, type: Float
 attr_accessible :time,:radius
end

时间字段包含应删除模型的实际时间.我该怎么做,我必须编写一个脚本将其放在cron作业中.但是我不想创建一个cron作业.有没有其他方法可以自动执行此操作,也可以在我可以定义的Rails模型中使用任何方法,还是仅在Rails中内置一些方法.我肯定会丢失一些东西.

The time field contain the actual time when model should be deleted. How can I do that , One idea I have to write a script put that in cron job. But I don't want to create a cron job. Is there any other way I can automate this or any method inside rails model I can define or something inbuilt into rails only. I am surely missing something.

您可以使用delay_job gem: https://github.com/collectiveidea/delayed_job

You can use delayed_job gem: https://github.com/collectiveidea/delayed_job

document.delay(run_at: time).destroy