Skip to main content

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.

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.
1

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
Once MongoDB is installed, make sure the mongod service is enabled so it starts automatically, or plan to start it manually in Step 5.
2

Clone the Repository

Clone the project from GitHub and move into the project directory:
git clone https://github.com/tutosrive/fastapi-CRUD-MongoDB.git && cd fastapi-CRUD-MongoDB
3

Create a Virtual Environment

Create an isolated Python virtual environment inside the project folder and activate it. The activation command differs by operating system:
python -m venv .venv
.venv\Scripts\activate
Your shell prompt will update with (.venv) to confirm the environment is active.
4

Install Dependencies

With the virtual environment active, install the pinned dependencies from requirements.txt:
pip install -r requirements.txt
This installs two packages:
PackageVersionPurpose
fastapi[standard]0.122.0Web framework — includes Pydantic v2 and Uvicorn.
pymongo4.15.4Official MongoDB driver for Python.
5

Start MongoDB

The application connects to MongoDB on localhost:27017 — the default address — with no extra configuration required. Start the MongoDB service if it is not already running:
# If installed as a service (most common)
net start MongoDB
You can verify the daemon is reachable by running mongosh — if it connects without error, you are good to go.
6

Run the Server

Start the API with Uvicorn. Choose the command that matches your workflow:Production (no auto-reload):
uvicorn main:app
Development (auto-reload on file changes, port 5000):
uvicorn main:app --reload --port 5000
You should see output similar to:
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Or, when using the dev command:
INFO:     Uvicorn running on http://127.0.0.1:5000 (Press CTRL+C to quit)
INFO:     Started reloader process using WatchFiles
7

Make Your First Request

With the server running, create your first User by sending a 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.
curl -X POST http://127.0.0.1:8000/users/ \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "age": 30, "email": "alice@example.com"}'
A successful response returns 200 OK with the newly created user, including the auto-generated MongoDB ObjectId serialised as a string:
{
  "id": "64f1a2b3c4d5e6f7a8b9c0d1",
  "name": "Alice",
  "age": 30,
  "email": "alice@example.com"
}
You can now retrieve Alice by her id:
curl http://127.0.0.1:8000/users/64f1a2b3c4d5e6f7a8b9c0d1
Or list all users:
curl http://127.0.0.1:8000/users/
Open http://127.0.0.1:8000/docs (or port 5000 if you used the dev command) to access the auto-generated Swagger UI. Every endpoint for Users and Tasks is listed there with interactive request forms — no additional tooling needed to explore the full API.

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.

Build docs developers (and LLMs) love