-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeleteDOcuments.py
More file actions
32 lines (25 loc) · 982 Bytes
/
Copy pathdeleteDOcuments.py
File metadata and controls
32 lines (25 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from pymongo import MongoClient
# MongoDB connection details
MONGO_URI = "mongodb://0.0.0.0:27017/"
DATABASE_NAME = "seniorDesignTesting"
COLLECTION_NAME = "sendAndRecievePlantInfoTest"
def connect_to_mongodb():
"""Connects to MongoDB and returns a client."""
client = MongoClient(MONGO_URI)
client.admin.command("ping") # Test connection
print("Connected successfully to MongoDB")
return client
def delete_all_documents():
"""Deletes all documents from the collection."""
client = connect_to_mongodb()
db = client[DATABASE_NAME]
collection = db[COLLECTION_NAME]
confirm = input("⚠️ Are you sure you want to delete ALL documents? (yes/no): ").strip().lower()
if confirm != "yes":
print(" Deletion aborted.")
return
result = collection.delete_many({})
print(f" Deleted {result.deleted_count} documents from '{COLLECTION_NAME}'.")
client.close()
if __name__ == "__main__":
delete_all_documents()