jefersondaniel/pydantic-mongo

Adding index support to the AbstractRepository

Opened this issue · 1 comments

Hi there :) cool library! I'm hoping to use it for a project, and had a question...

I'm wondering if there's any chance of supporting MongoDB indexing as a Meta field of the repository. Right now (unless I'm mistaken) you'd have to manually do this via your MongoDB connection, instead of defining it on your model.

For example we could have something like this:

class SpamRepository(AbstractRepository[Spam]):
    class Meta:
        collection_name = 'spams'
        collection_indexes = [
            { "key": "field1", "direction": pymongo.DESCENDING, "options": { } }
        ]

We should be able to pass those indexes straight into pymongo to add them automatically, I think?

Thank you for reading 🙏

@jefersondaniel slight nudge... wondering for your thoughts on this!