Create mongoconnection.py
Browse files
components/mongoconnection.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo.mongo_client import MongoClient
|
| 2 |
+
from pymongo.server_api import ServerApi
|
| 3 |
+
uri = "mongodb+srv://junaid:junaid@cluster0.0ec6y.mongodb.net/?appName=Cluster0"
|
| 4 |
+
# Create a new client and connect to the server
|
| 5 |
+
client = MongoClient(uri, server_api=ServerApi('1'))
|
| 6 |
+
# Send a ping to confirm a successful connection
|
| 7 |
+
try:
|
| 8 |
+
client.admin.command('ping')
|
| 9 |
+
print("Pinged your deployment. You successfully connected to MongoDB!")
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(e)
|
| 12 |
+
|
| 13 |
+
def provideClient():
|
| 14 |
+
return client
|