Skip to content

Instantly share code, notes, and snippets.

@Kjdragan
Created February 24, 2025 15:53
Show Gist options
  • Save Kjdragan/8ff23e009700fce7dc1f259386eb4e5d to your computer and use it in GitHub Desktop.
Save Kjdragan/8ff23e009700fce7dc1f259386eb4e5d to your computer and use it in GitHub Desktop.
MONGO_DB
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