File size: 373 Bytes
4d1746c
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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"]