Last active
September 12, 2022 18:45
-
-
Save jchenj/ca3738dd34b58310e055b140fe9faa9d to your computer and use it in GitHub Desktop.
Python-connection
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
| 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