Reputation: 57
I had been using motor https://motor.readthedocs.io/en/stable/ as my driver in fastapi application to handle asynchronous db calls. But with scale, i required proper ODM support in mongodb. I had gone through multiple available odm options like beanie, motor engine and more. Some of them don't look matured (little fork and contributors). I am not saying being unpopular, the project is not useful but since i am using this in production i need some concrete and stable ODM for this. What are you guys using for such purpose and please suggest me if there is any custom way too. Thanks
Upvotes: 2
Views: 1213
Reputation: 1908
Beanie: https://beanie-odm.dev
First, it is async (uses the official Motor driver), which is a must if you want to use async endpoints with FastAPI (most operations are I/O).
Beanie allows us to define models and enforce schemas at the application level (with Pydantic and PydancticV2) and works great with the FastAPI data validation (both are using Pydantic).
It also provides simple methods for interacting with the DB (e.g., model.insert(), model.get()).
Give it a shot ! :)
Upvotes: 3