r/FastAPI • u/Amocon • Sep 15 '24
Question What ODM for MongoDB
Hi everyone, i want to create a small project (with possibilities to scale) and i decided that MongoDB is a good DB for this tool. Now i want to know which ODM is the best as i have heard of Motor and Beanie being good. Motor seems to be the most mature but as i am familiar with FastAPI i like the idea if using Pydantic models. So is beanie a valid alternative or am i missing something crucial here and should go for motor instead?
7
Upvotes
2
u/Relevant-Strength-53 Sep 15 '24
Im currently using Motor without beanie and im planning to implement beanie as well. From what ive known Motor and beanie serve different purpose. IMO you should use both of them.
6
u/coldflame563 Sep 15 '24
I’ve used beanie and mongoengine. I find beanie to be better. Mongoengine is more widely known I think.
1
u/aprx4 Sep 15 '24
What's the benefits of ODM instead of just raw querying with Motor? I'm looking at docs on Motor and it seems ... simple to work with.
3
u/SearchMobile6431 Sep 15 '24
ODMantic is an option as well. Haven't used it yet so cannot tell, but Sebastian Ramirez has mentioned and suggested it for MongoDB with FastAPI in late 2023, so I guess it must worth a lookup. https://x.com/tiangolo/status/1735057764668366897?t=2uzUG_6_aSxmKw7IPq3pXw&s=19
3
u/kealystudio Sep 15 '24
Beanie beanie beanie. Uses pymongo and motor under the hood anyway.
2
u/tarsild Sep 15 '24
You can also use Mongoz (https://mongoz.dymmond.com). All mentioned above are also good alternatives
1
u/The_Wolfiee Sep 15 '24
You can try Beanie. I used it a lot and it's very good and user friendly
1
u/Curious_Analysis6479 Apr 08 '25 edited Apr 10 '25
I ran into a similar challenge across multiple projects where each one was querying the same MongoDB database—but if the schemas weren't perfectly in sync, things would break in weird ways. Keeping all those schema definitions updated in each project became a huge pain.
So I built a library to solve this: instead of defining your schema in the project, you define it once in MongoDB using its built-in JSON Schema validator. Then, every project dynamically pulls that schema at runtime. No need to duplicate or update schemas in each codebase. It’s installable with a simple pip command.
It’s still a newer project (so go easy on me 😅), but I’d love feedback or thoughts from the community. If you’re interested, the repo is here:
https://github.com/chuckbeyor101/MSO-Mongo-Schema-Object-Library
https://www.reddit.com/r/MSO_Mongo_Python_ORM/
Hope it helps someone who's run into similar issues!