This quickstart walks you through everything you need to go from a fresh clone to a running server and a successful API call. By the end you will have the FastAPI CRUD MongoDB application serving requests on your machine and a User record created in your local MongoDB database.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/fastapi-CRUD-MongoDB/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Ensure the following are installed on your machine before continuing:
- Python 3.10 or newer — verify with
python --version. - MongoDB Community Edition — the API connects to a local MongoDB instance with no authentication. Download and install it from the official page: mongodb.com/try/download/community
mongod service is enabled so it starts automatically, or plan to start it manually in Step 5.Create a Virtual Environment
Create an isolated Python virtual environment inside the project folder and activate it. The activation command differs by operating system:Your shell prompt will update with
- Windows
- Linux / macOS
(.venv) to confirm the environment is active.Install Dependencies
With the virtual environment active, install the pinned dependencies from This installs two packages:
requirements.txt:| Package | Version | Purpose |
|---|---|---|
fastapi[standard] | 0.122.0 | Web framework — includes Pydantic v2 and Uvicorn. |
pymongo | 4.15.4 | Official MongoDB driver for Python. |
Start MongoDB
The application connects to MongoDB on You can verify the daemon is reachable by running
localhost:27017 — the default address — with no extra configuration required. Start the MongoDB service if it is not already running:- Windows
- Linux / macOS
mongosh — if it connects without error, you are good to go.Run the Server
Start the API with Uvicorn. Choose the command that matches your workflow:Production (no auto-reload):Development (auto-reload on file changes, port 5000):You should see output similar to:Or, when using the dev command:
Make Your First Request
With the server running, create your first User by sending a A successful response returns You can now retrieve Alice by her Or list all users:
POST request to /users/. The id field is optional in the request body — MongoDB assigns it automatically and the API returns the full object including the generated id.200 OK with the newly created user, including the auto-generated MongoDB ObjectId serialised as a string:id:What’s Next
API Reference
Browse the complete endpoint reference for all User and Task operations, including request bodies, path parameters, and response schemas.
Data Models
Understand the Pydantic models, MongoDB serialisation schemas, and the difference between
Task and TaskUpdate.