mongodb TTL不删除文档 [英] mongodb TTL not removing documents

查看:77
本文介绍了mongodb TTL不删除文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的架构,例如:

I have a simple schema like:

{
    _id: String,      // auto generated
    key: String,      // there is a unique index on this field
    timestamp: Date() // set to current time
}

然后我像这样设置TTL索引:

Then I set the TTL index like so:

db.sess.ensureIndex( { "timestamp": 1 }, { expireAfterSeconds: 3600 } )

我希望记录在1小时后被删除,但它永远不会被删除. 我打开了详细的日志记录,然后看到TTLMonitor正在运行:

I expect the record to removed after 1 hour but it is never removed. I flipped on verbose logging and I see the TTLMonitor running:

Tue Sep 10 10:42:37.081 [TTLMonitor] TTL: { timestamp: 1.0 } { timestamp: { $lt: new Date(1378823557081) } }
Tue Sep 10 10:42:37.081 [TTLMonitor] TTL deleted: 0

当我自己运行该查询时,我看到所有过期的记录都将返回:

When I run that query myself I see all my expired records coming back:

db.sess.find({ timestamp: { $lt: new Date(1378823557081) }})

...

有什么想法吗?我很困惑.

Any ideas? I'm stumped.

编辑-下面的示例文档

{ "_id" : "3971446b45e640fdb30ebb3d58663807", "key" : "6XTHYKG7XBTQE9MJH8", "timestamp" : ISODate("2013-09-09T18:54:28Z") }

推荐答案

  1. 您能告诉我们插入记录的实际外观吗?

  1. Can you show us what the inserted records actually look like?

从不"持续多长时间?因为有个大警告:

How long is "never"? Because there's a big warning:

警告:TTL索引不能保证过期的数据将立即被删除.从文档过期到MongoDB从数据库中删除文档之间可能会有一段时间.

Warning: The TTL index does not guarantee that expired data will be deleted immediately. There may be a delay between the time a document expires and the time that MongoDB removes the document from the database.

  • 时间戳字段是否已有索引?

  • Does the timestamp field have an index already?

    这篇关于mongodb TTL不删除文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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