Spaces:
Sleeping
Sleeping
| # database.py | |
| # ββ MongoDB connection using PyMongo ββββββββββββββββββββββββββ | |
| # | |
| # We use a simple module-level client so all route files | |
| # can import the same `db` object without reconnecting. | |
| from pymongo import MongoClient | |
| from pymongo.errors import ConfigurationError | |
| from config import Config | |
| # Connect to MongoDB | |
| client = MongoClient(Config.MONGO_URI) | |
| # Select the database | |
| try: | |
| db = client.get_database() | |
| except ConfigurationError: | |
| db = client.get_database("nutritrack_advanced") | |
| # ββ Collections βββββββββββββββββββββββββββββββββββββββββββββββ | |
| # db.users β user profiles (name, birthdate, height, weight) | |
| # db.intake β daily food intake entries | |
| print(f"OK MongoDB connected: '{db.name}'") | |