Spaces:
Sleeping
Sleeping
Create components/dbconnection.py
Browse files- components/dbconnection.py +18 -0
components/dbconnection.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo import MongoClient
|
| 2 |
+
from pymongo.server_api import ServerApi
|
| 3 |
+
|
| 4 |
+
# The connection URI
|
| 5 |
+
uri = "mongodb+srv://junaid:junaid@cluster0.0ec6y.mongodb.net/?appName=Cluster0"
|
| 6 |
+
|
| 7 |
+
# Create a new client and connect to the server
|
| 8 |
+
# Note: server_api is optional but used here to match your Node.js 'ServerApiVersion.v1'
|
| 9 |
+
client = MongoClient(uri, server_api=ServerApi('1'))
|
| 10 |
+
|
| 11 |
+
def provide_client():
|
| 12 |
+
"""
|
| 13 |
+
Returns the MongoDB client instance.
|
| 14 |
+
"""
|
| 15 |
+
return client
|
| 16 |
+
|
| 17 |
+
# Example of how to export/use in another file:
|
| 18 |
+
# from your_filename import provide_client
|