Spaces:
Sleeping
Sleeping
Update db.py
Browse files
db.py
CHANGED
@@ -1,9 +1,25 @@
|
|
1 |
-
from pymongo import MongoClient
|
2 |
-
|
3 |
-
# MongoDB URI with actual credentials
|
4 |
-
CONNECTION_STRING = "mongodb+srv://transpolymer:transpolymer365@cluster0.2ojpls3.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
|
5 |
-
|
6 |
-
# Function to get the database
|
7 |
-
def get_database():
|
8 |
-
client = MongoClient(CONNECTION_STRING)
|
9 |
-
return client["transpolymerDB"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pymongo import MongoClient
|
2 |
+
|
3 |
+
# MongoDB URI with actual credentials
|
4 |
+
CONNECTION_STRING = "mongodb+srv://transpolymer:transpolymer365@cluster0.2ojpls3.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"
|
5 |
+
|
6 |
+
# Function to get the database
|
7 |
+
def get_database():
|
8 |
+
client = MongoClient(CONNECTION_STRING)
|
9 |
+
return client["transpolymerDB"]
|
10 |
+
|
11 |
+
# Get users collection
|
12 |
+
db = get_database()
|
13 |
+
users_collection = db["users"]
|
14 |
+
|
15 |
+
# Insert a new user
|
16 |
+
def insert_user(user_data):
|
17 |
+
users_collection.insert_one(user_data)
|
18 |
+
|
19 |
+
# Find a user by email
|
20 |
+
def find_user_by_email(email):
|
21 |
+
return users_collection.find_one({"email": email})
|
22 |
+
|
23 |
+
# ✅ ADD THIS: Find a user by username
|
24 |
+
def find_user_by_username(username):
|
25 |
+
return users_collection.find_one({"username": username})
|