Created
February 24, 2025 15:53
-
-
Save Kjdragan/8ff23e009700fce7dc1f259386eb4e5d to your computer and use it in GitHub Desktop.
MONGO_DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pymongo.mongo_client import MongoClient | |
| from pymongo.server_api import ServerApi | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| uri = f"mongodb+srv://kevin:{os.getenv('DB_PASSWORD')}@cluster0.5wqv7.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0" | |
| # Create a new client and connect to the server | |
| client = MongoClient(uri, server_api=ServerApi('1')) | |
| # Send a ping to confirm a successful connection | |
| try: | |
| client.admin.command('ping') | |
| print("Pinged your deployment. You successfully connected to MongoDB!") | |
| except Exception as e: | |
| print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment