3.3 KiB
3.3 KiB
PIF Compiler - MongoDB Docker Setup
Quick Start
Start MongoDB and Mongo Express web interface:
cd utils
docker-compose up -d
Stop the services:
docker-compose down
Stop and remove all data:
docker-compose down -v
Services
MongoDB
- Port: 27017
- Database: toxinfo
- Username: admin
- Password: admin123
- Connection String:
mongodb://admin:admin123@localhost:27017/toxinfo?authSource=admin
Mongo Express (Web UI)
- URL: http://localhost:8082
- Username: admin
- Password: admin123
Usage in Python
Update your MongoDB connection in src/pif_compiler/functions/mongo_functions.py:
# For local development with Docker
db = connect(user="admin", password="admin123", database="toxinfo")
Or use the connection URI directly:
from pymongo import MongoClient
client = MongoClient("mongodb://admin:admin123@localhost:27017/toxinfo?authSource=admin")
db = client['toxinfo']
Data Persistence
Data is persisted in Docker volumes:
mongodb_data- Database filesmongodb_config- Configuration files
These volumes persist even when containers are stopped.
Creating Application User
It's recommended to create a dedicated user for your application instead of using the admin account.
Option 1: Using mongosh (MongoDB Shell)
# Access MongoDB shell
docker exec -it pif_mongodb mongosh -u admin -p admin123 --authenticationDatabase admin
# In the MongoDB shell, run:
use toxinfo
db.createUser({
user: "pif_app",
pwd: "pif_app_password",
roles: [
{ role: "readWrite", db: "toxinfo" }
]
})
# Exit the shell
exit
Option 2: Using Mongo Express Web UI
- Go to http://localhost:8082
- Login with admin/admin123
- Select
toxinfodatabase - Click on "Users" tab
- Add new user with
readWriterole
Option 3: Using Python Script
Create a file utils/create_user.py:
from pymongo import MongoClient
# Connect as admin
client = MongoClient("mongodb://admin:admin123@localhost:27017/?authSource=admin")
db = client['toxinfo']
# Create application user
db.command("createUser", "pif_app",
pwd="pif_app_password",
roles=[{"role": "readWrite", "db": "toxinfo"}])
print("User 'pif_app' created successfully!")
client.close()
Run it:
cd utils
uv run python create_user.py
Update Your Application
After creating the user, update your connection in src/pif_compiler/functions/mongo_functions.py:
# Use application user instead of admin
db = connect(user="pif_app", password="pif_app_password", database="toxinfo")
Or with connection URI:
client = MongoClient("mongodb://pif_app:pif_app_password@localhost:27017/toxinfo?authSource=toxinfo")
Available Roles
read: Read-only access to the databasereadWrite: Read and write access (recommended for your app)dbAdmin: Database administration (create indexes, etc.)userAdmin: Manage users and roles
Security Notes
⚠️ WARNING: The default credentials are for local development only.
For production:
- Change all passwords in
docker-compose.yml - Use environment variables or secrets management
- Create dedicated users with minimal required permissions
- Configure firewall rules
- Enable SSL/TLS connections