Question

I want to use 'Time To Live' collection feature (http://docs.mongodb.org/manual/tutorial/expire-data/) in my app (flask+mongokit).

It is possible to create TTL index for all documents in collection via MongoKit when i describe my models or i need to use pymongo instead?

Thanks

Was it helpful?

Solution

You can use the pymongo layer to create a TTL index for all documents:

http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.ensure_index

Exemple assuming that you have a User mongokit model:

db.User.collection.ensure_index("name", 300)

note that TTL is now deprecated in pymongo 2.3. Use cache_for instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top