Building the backend with FastAPI and Beanie
For simplicity’s sake and to make the application as illustrative as possible, the API that you will build in this chapter will not differ too much from the one built in Chapter 7, Building a Backend with FastAPI. This way, you will be able to naturally pick up the main differences in the approaches of using Motor (or PyMongo) directly and the Beanie ODM.
Object-Relational Mappers (ORMs) and ODMs are tools whose main purpose is to abstract the underlying database (whether it’s a relational or non-relational database) and facilitate the development process. Some famous Python examples include the Django ORM and SQLAlchemy—two proven and battle-tested solutions—as well as SQLModel, which was created by the creator of FastAPI and tightly integrated into the FastAPI/Pydantic world.
Two modern ODMs that are gaining traction and popularity among the Python and MongoDB community are Beanie (https://beanie-odm.dev...