Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mongodb TTL not removing documents

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
}

Then I set the TTL index like so:

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

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.

EDIT - Example document below

{ "_id" : "3971446b45e640fdb30ebb3d58663807", "key" : "6XTHYKG7XBTQE9MJH8", "timestamp" : ISODate("2013-09-09T18:54:28Z") }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Can you show us what the inserted records actually look like?

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

    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.

  3. Does the timestamp field have an index already?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...