pythondjangomongodbdjongo

Djongo+Mongo add expiration (auto-delete) to model objects


Is there a simple way in Django to add an expiration date to documents via the model meta?

For example, in pymongo you can do something like this:

mongo_col.ensure_index("date", expireAfterSeconds=3*60)

Solution

  • My best solution so far was to add the field in the model:

    --- my_model.py ---

        ...
        objects = models.DjongoManager()
        ...
    

    And then just somewhere in the code:

    MyModel.objects.mongo_create_index("created", expireAfterSeconds=60*60);