mongodb - Expire a Collection in Mongo using Casbah EnsureIndex -
i attempting expire collection in mongo using casbah's ensureindex api.
based on document http://docs.mongodb.org/manual/tutorial/expire-data/
i using casbah's proposed ensureindex api
collection.ensureindex(dbobject("status" -> 1, "expireafterseconds" -> 120))
to expire collection in 2 minutes ...
the collection not being evicted or expired.
am missing else here?
thanks
there couple things check:
- were following docs t , tried create index on
status
field doesn't exist in documents? (had atleast ask...) - does
status
field containdates
? can theoretically mixed, documents date type considered expiration. - have checked collection indexes make sure index created?
to check index console run: db.collection.getindexes()
. if index created successfully, double check have corresponding status
fields in documents , proper dates.
adding index alone, doesn't create date field - need add documents or use existing date field not part of other index.
also note, docs:
ttl indexes expire data removing documents in background task runs every 60 seconds
so, if have 120 second
expiration, bear in mind, possible documents remain 120 seconds
179 seconds
, give or take, depending on when document expired , background task last ran.
edit: noted in comments - collection cannot removed based on ttl index, index expires documents in collection.
Comments
Post a Comment