BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.91k stars 201 forks source link

How add TTL to index on document? #326

Closed IProudNoob closed 1 year ago

IProudNoob commented 1 year ago

Hello! It is possible to add TTL to the index?

THX!

rgajason commented 1 year ago

You can create advanced indexes by referencing pymongo.IndexModel directly:

https://roman-right.github.io/beanie/tutorial/indexes-%26-collection-names/#multi-field-indices

For example, if you wanted to create a partial index:

class Settings:
    indexes = [
        IndexModel(
            [("email", ASCENDING)],
            name="email_unique_if_not_empty",
            unique=True,
            partialFilterExpression={"email": {"$type": "string"}},
        ),

If you can create the index you seek with IndexModel, you can do the same with Beanie:

https://pymongo.readthedocs.io/en/stable/api/pymongo/operations.html#pymongo.operations.IndexModel

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 14 days with no activity.