-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (41 loc) · 799 Bytes
/
app.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pymongo
conn = pymongo.MongoClient("mongodb://localhost:27017/")
db = conn["ma_base"]["test"]
#insert
D = {"_id":0,"Lname":"ZKARA","Fname":"Salah Eddine","age":19}
L = []
for i in range(1,10):
D = {"_id":i,"Lname":"ZKARA","Fname":"Salah Eddine","age":20}
L.append(D)
try:
db.insert_many(L)
print("Succes!")
except Exception as e:
print("ERROR!!")
#find
filter={
'age': 20
}
limit=3
result = db.find(
filter=filter,
limit=limit
)
filtre = {}
resultat = db.find(filtre)
for r in result:
print(r)
#update
try:
query = {"age":20}
newval = {"$set": {"age":54}}
db.update_many(query,newval)
print("Ok")
except Exception as e:
print("ERROR!")
#delete
delete_filter = {"age":54}
db.delete_one(delete_filter)
db.delete_many(delete_filter)
#delete collection
db.drop()