-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFirtMongo.py
More file actions
35 lines (28 loc) · 1 KB
/
FirtMongo.py
File metadata and controls
35 lines (28 loc) · 1 KB
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
33
34
import pymongo
connection=pymongo.MongoClient("localhost",27017)
database = connection["my_db1"]
collection_nameAndPw = database["nameAndPw"]
myquery ={"hint":"unknowuser"}
class ToDelete:
def __init__(self,myquery):
self.toDelete= myquery
def delete(self):
try:
data = collection_nameAndPw.delete_one(self.toDelete)
print("Deleted Documents:", data.deleted_count)
except Exception as err:
print(err)
def print_data(self):
try:
all_data = collection_nameAndPw.find()
for i in all_data:
print(i)
except Exception as err:
print(err)
if __name__ =="__main__":
process=ToDelete(myquery)
print("Before Delete:")
process.print_data()
process.delete()
print("After delete data:")
process.print_data()