I'm going to build a sample CRUD with FastAPI and MongoDB. Using this sample to understand how to connect FastAPI with MongoDB.
git clone https://github.com/bsthen/Sample-CRUD-FastAPI-MongoDB.git && cd Sample-CRUD-FastAPI-MongoDB
Create a virtual environment:
python3 -m venv env
Or looking for install virtual envirometns link here.
Activate ENV for Linux or macOS
source env/bin/activate
Or
Activate ENV for Windows
\env\Scripts\activate.bat
Install Dependencies
pip3 install -r requirements.txt
uvicorn main:app --reload
Open http://localhost:8000/docs/
please copy sample.env and rename it to .env and replace your mongodb connection url.