Hi Vladimir,
There is no way to TTL or automatically drop a collection in MongoDB.
The best way of automatically removing a collection after a set period would be a scheduled job outside of MongoDB - for example, through a system job (e.g. cron or Windows Task Scheduler) or a job within your application.
Regarding your disk space, when documents are dropped, the disk space will not be returned to the filesystem. However, that disk space can be reused by MongoDB, depending on the size of of the new document and the level of fragmentation. You can also use db.repairDatabase() to reclaim the free space in your MongoDB database and return it to the filesystem, however, this requires free disk space equal to the current on-disk size of the database.
Another way of approaching this problem might be to create databases based on dates, for example:
- cats_20140101
- cats_20140102
- cats_20140103
- cats_20140104
You could then have a script to automatically drop databases based on dates (e.g. older than 4 days ago), which would also return the disk space afterwards.
Regards,
Victor