Starting with 2.1 (2.2 for stable), MongoDB allows collections to have a Time To Live to be set with ensureIndex() to be automatically expired.

This could allow actual server based cleaning without any PHP code.

http://docs.mongodb.org/manual/tutorial/expire-data/

Comments

fgm’s picture

Come to think of it, some might even be interested in them for the watchdog: they are an alternative to capped collections in some scenarii.

fgm’s picture

Issue summary:View changes

The 2.1/2.2 implementation allowed only a single duration for a given index. Since 2.3/2.4 it is possible to specify expireAfterSeconds as 0, and insert the expiration timestamp in the documents themselves so the deletion thread will delete documents at their requested expiration, which seems just ideal.

http://docs.mongodb.org/v2.4/tutorial/expire-data/#expire-documents-at-a...

fgm’s picture

After experimenting with it, using the latter option seems especially interesting, as it removes the need for an explicit flushing operation, which is performed by the MongoDB server in the background.

Some remarks before committing to this, though:

  • the expiration is performed by the TTLMonitor, which only runs every 60 seconds, so shorter expiration times will not be covered
  • the TTLMonitor can be disabled from the command line --setParameter ttlMonitorEnabled=false or by a command db.adminCommand({setParameter:1, ttlMonitorEnabled:false}), so its availability should be checked in the requirements

This does not seem to be an actual problem, though.