Skip to content

Instantly share code, notes, and snippets.

@jchenj
Last active September 12, 2022 18:45
Show Gist options
  • Select an option

  • Save jchenj/ca3738dd34b58310e055b140fe9faa9d to your computer and use it in GitHub Desktop.

Select an option

Save jchenj/ca3738dd34b58310e055b140fe9faa9d to your computer and use it in GitHub Desktop.
Python-connection
import os
from dotenv import load_dotenv
from pymongo import MongoClient, errors
# Load config from .env file
load_dotenv()
MONGODB_URI = os.environ["MONGODB_URI"]
try:
client = MongoClient(MONGODB_URI)
for db_name in client.list_database_names():
print(db_name)
client.close()
except errors.ServerSelectionTimeoutError as err:
print ("connection error", err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment