pydantic-mongo icon indicating copy to clipboard operation
pydantic-mongo copied to clipboard

Adding index support to the AbstractRepository

Open whitfin opened this issue 8 months ago • 0 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 🙏

whitfin avatar Jun 07 '24 00:06 whitfin