-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase_test.py
More file actions
111 lines (87 loc) · 3.43 KB
/
Copy pathdatabase_test.py
File metadata and controls
111 lines (87 loc) · 3.43 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from pymongo import MongoClient
def delete_user(collection, username,id):
if(id!=-1):
collection.delete_many({"_id": id})
else:
collection.delete_many({"name": username})
print(username, " User information deleted from the database.")
def delete_user1(collection, username,id):
if (id != -1):
collection.delete_many({"_id": id})
else:
collection.delete_many({"name": username})
print(username, " User information deleted from the database1.")
def get_user(collection, username):
user = collection.find_one({"name": username})
print("username found ",user)
return user
def get_user1(collection, username):
user = collection.find_one({"name": username})
print("username found ", user)
return user
def update_user(collection, id, username, score, position):
p1 = {"_id": id, "name": username, "score": score, "position": position}
collection.update_one(
{"_id": id},
{"$set": p1},
upsert=True
)
print(username, " User information updated from the database.")
def update_user1(collection, id, username, score, position):
p1 = {"_id": id, "name": username, "score": score, "position": position}
collection.update_one(
{"_id": id},
{"$set": p1},
upsert=True
)
def DB(id, username, score, position, delFlag,quitted,LostConnection):
collection1 = MongoClient(
"mongodb://amirrmamdouh:123@ac-l1zkv5z-shard-00-00.g8t8zzf.mongodb.net:27017,ac-l1zkv5z-shard-00-01.g8t8zzf.mongodb.net:27017,ac-l1zkv5z-shard-00-02.g8t8zzf.mongodb.net:27017/?ssl=true&replicaSet=atlas-xsrnrq-shard-0&authSource=admin&retryWrites=true&w=majority")
collection2 = MongoClient(
"mongodb://Mirna:123@ac-pdcgmvi-shard-00-00.z9x8y2q.mongodb.net:27017,ac-pdcgmvi-shard-00-01.z9x8y2q.mongodb.net:27017,ac-pdcgmvi-shard-00-02.z9x8y2q.mongodb.net:27017/?ssl=true&replicaSet=atlas-83vr9r-shard-0&authSource=admin&retryWrites=true&w=majority")
cluster = collection1
db = cluster['Clients']
collection1 = db['Records']
cluster1 = collection2
db1 = cluster1['Clients']
collection2 = db1['Records']
if delFlag == 1:
try:
delete_user(collection1, username,-1)
except:
print("dbDelete0 failed")
try:
delete_user1(collection2, username,-1)
except:
print("dbDelete1 failed")
elif delFlag==0:
try:
update_user(collection1, id, username, score, position)
print("db update0 successful")
except:
print("db update0 failed")
try:
update_user1(collection2, id, username, score, position)
print("db update1 successful")
except:
print("db update1 failed")
if(quitted!=None and len(quitted)!=0):
for i in range(len(quitted)):
try:
delete_user(collection1,None ,quitted[i])
except:
print("delete quitted failed db0")
try:
delete_user1(collection2,None ,quitted[i])
except:
print("delete quitted failed db1")
if(LostConnection==1):
print("bengyb el old user aho")
try:
return get_user(collection1,str(username))
except:
print("except of getting user")
try:
return get_user1(collection2,str(username))
except:
print("except of getting user")