铁轨中的mongoid TTL

时间:2012-08-08 07:44:55

标签: ruby-on-rails ruby mongodb mongoid

正如mongodb网站所述,我可以使用.ensureIndex({state:1},{expireAfterSeconds:10})使记录失效。但是如何通过rails实现这一点?感谢

1 个答案:

答案 0 :(得分:3)

如果您使用的是MongoDB 2.2,那么Ruby驱动程序应该已经通过Collection的create_index()ensure_index()方法支持了这一点。索引选项直接传递给服务器。 API文档中的下划线符号在内部被翻译为方便(例如:drop_dups设置:dropDups选项)。你应该能够做到:

@collection.create_index([['state', Mongo::ASCENDING]], :expireAfterSeconds => 10)

具体来说,对于mongoid,看起来你也可以按this documentation传递索引的自定义选项。

相关问题