MongoDB
Last updated
Was this helpful?
Was this helpful?
!pip install pymongo
import os
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
uri = f'mongodb+srv://{os.environ.get("MONGO_USER")}:{os.environ.get("MONGO_PASS")}@{os.environ.get("MONGO_HOST")}/?retryWrites=true&w=majority'
# Create a new client and connect to the server
client = MongoClient(uri, server_api=ServerApi('1'))try:
client.admin.command('ping')
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e)