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-MongoDBCreate a virtual environment:
python3 -m venv envOr looking for install virtual envirometns link here.
Activate ENV for Linux or macOS
source env/bin/activateOr
Activate ENV for Windows
\env\Scripts\activate.batInstall Dependencies
pip3 install -r requirements.txtuvicorn main:app --reloadOpen http://localhost:8000/docs/
please copy sample.env and rename it to .env and replace your mongodb connection url.