Spaces:
Running
Running
from pymongo import MongoClient | |
from pymongo.server_api import ServerApi | |
import os | |
uri = os.getenv('DATABASE_URL').strip() | |
cluster = MongoClient(uri, server_api=ServerApi('1')) | |
try: | |
cluster.admin.command('ping') | |
print("Pinged your deployment. You successfully connected to MongoDB!") | |
except Exception as e: | |
print(e) | |
db = cluster["test"] | |
collection = db["test"] |