Simple Python program support Mongo database creation using direct access or via object Class
Syntax | Description |
---|---|
Implementation of the API using FastAPI | |
Data storage of the entities created through the API | |
Provide the required local environment in a container |
Install Python virtual enviornment and required modules:
apt install -y python3.10-venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt # include PyMongo
deactivate
docker-compose up -d
source .venv/bin/activate
python initdb.py # create user database
python test.py # test database operation
deactivate
docker-compose down
export APP_CONFIG_MONGODB_URL="mongodb://username:password@localhost:27017/"
export APP_CONFIG_MONGODB_URL="mongodb://localhost:27017/"
export APP_CONFIG_MONGODB_NAME="database"
"APP_CONFIG_MONGODB_URL" : "mongodb://localhost:27017/"
"APP_CONFIG_MONGODB_URL" : "mongodb://username:password@localhost:27017/"
"APP_CONFIG_MONGODB_NAME" : "database"
- initdb.py : To load initalize data from file ./init_data/data.json
- test.py : To test the function of Class
- data.json : initalize user data to setup the database.
- setting.json : configuration file
- __init__.py : python module folder
- db.py : Class Datasource
- user.py : Class User