Junaidb commited on
Commit
ab9b9f6
·
verified ·
1 Parent(s): 913ffb3

Create mongoconnection.py

Browse files
Files changed (1) hide show
  1. components/mongoconnection.py +14 -0
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