Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions database_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from bson import ObjectId
from pymongo import MongoClient

client = MongoClient('mongodb+srv://[USERNAME:PASSWORD]@fireguardproject.ggfqm.mongodb.net/')
db = client['sample_mflix']
# Check if 'users' collection exists
def collection_exists(db, collection_name):
try:
# Attempt to list collection names
collections = db.list_collection_names()
except Exception as e:
print(f"An error occurred: {e}")
return False

return collection_name in collections

# Check if 'users' collection exists
if collection_exists(db, 'users'):
users_collection = db['users']
print("The 'users' collection exists.")
else:
print("The 'users' collection does not exist.")



def create_user(user_data):
result = users_collection.insert_one(user_data)
return result.inserted_id

def get_user(user_id):
return users_collection.find_one({"_id": ObjectId(user_id)})


user = get_user("59b99db4cfa9a34dcd7885b7")

print(user.get("name"))

100 changes: 100 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package-mode = false
[tool.poetry.dependencies]
python = ">=3.11, <4.0"
flake8 = "^7.1.2"
pymongo = "^4.11.2"
dynamic-frcm = "^1.0.1"

[build-system]
Expand Down
Loading