Spaces:
Sleeping
Sleeping
| import motor.motor_asyncio | |
| import os | |
| # dotenv allows us to read the .env file | |
| from dotenv import load_dotenv | |
| # 1. Load the secrets | |
| load_dotenv() | |
| # 2. Grab the URL from the environment | |
| MONGO_URL = os.getenv("MONGODB_URL") | |
| DB_NAME = os.getenv("DB_NAME") | |
| # Safety Check: Did we forget the .env file? | |
| if not MONGO_URL: | |
| raise ValueError("No MONGODB_URL found. Did you create the .env file?") | |
| # 3. Create the Client (The Connector) | |
| client = motor.motor_asyncio.AsyncIOMotorClient(MONGO_URL) | |
| # 4. Select the Database | |
| db = client[DB_NAME] | |
| # 5. Define Collections (Think of these like folders for your data) | |
| users_collection = db.get_collection("users") | |
| articles_collection = db.get_collection("articles") | |
| feedback_collection = db.get_collection("feedback") |