What are some best practices for Fastapi + Mongodb
bengabp opened this issue · 2 comments
Almost all of of here have used some ORM library like Sqlalchemy which is equivalent to how django does its things. I found myself using mongodb as the main database choice for most of my projects. Also in all company projects that Ive been working on since this year, I have not used any sql database. I usually use pymongo
and Its always a hassle to configure everything for every new project. What ive done is create a DBConnection class which has all the collections I need as class attributes and possibly some methods does some db operations.
The problem
As you already figured out, Its nothing close to using an ORM, Are there some libraries that support ODM that i can use in fastapi like Sqlalchemy (when dealing with SQL). I mean relationsips, and most important being able to still my favourite mongodb operation which is the aggregate
searches.
If you're looking for an ODM compatible with FastAPI and Pydantic, you would definitively like this one: https://beanie-odm.dev/