-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.py
36 lines (28 loc) · 895 Bytes
/
db.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
import pymongo
conn_str = "Your Connection String"
client = pymongo.MongoClient(conn_str)
db = client["Organisation"]
employeeCollection = db["employees"]
def add_employee(data):
data = dict(data)
response = employeeCollection.insert_one(data)
return str(response.inserted_id)
def all( ):
response = employeeCollection.find({})
data = [ ]
for emp in response:
emp["_id"] = str(emp["_id"])
data.append(emp)
return data
def get_one(email):
response = employeeCollection.find_one({'email':email})
response["_id"] = str(response["_id"])
return response
def update(data):
data = dict(data)
response = employeeCollection.update_one({"email": data["email"]},
{"$set": data})
return response.modified_count
def delete(email):
response = employeeCollection.delete_one({"email":email})
return response.deleted_count