mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-14 18:58:10 +08:00

* Implement MongoDB adapter using motor * Add mongo container to build pipeline * Tidy up dependencies * Update documentation for MongoDB * Export MongoDB adapter from db package * Pass black format * Update README
1.0 KiB
1.0 KiB
MongoDB
FastAPI Users provides the necessary tools to work with MongoDB databases thanks to mongodb/motor package for full async support.
Setup database connection and collection
Let's create a MongoDB connection and instantiate a collection.
{!./src/db_mongodb.py!}
You can choose any name for the database and the collection.
Create the database adapter
The database adapter of FastAPI Users makes the link between your database configuration and the users logic. Create it like this.
{!./src/db_mongodb.py!}
!!! info
The database adapter will automatically create a unique index on id
and email
.
!!! warning
FastAPI Users will use its defined id
UUID-string as unique identifier for the user, rather than the builtin MongoDB _id
.
Next steps
We will now configure an authentication method.