-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
26 lines (18 loc) · 738 Bytes
/
Copy pathdb.py
File metadata and controls
26 lines (18 loc) · 738 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
from pymongo import MongoClient
from credentials import mongodb
class Database():
def __init__(self, collection):
# self.client = MongoClient('mongodb://{}:{}'.format(mongodb['host'],mongodb['port']))
self.client = MongoClient('localhost',27017)
self.collection = self.client['face_recognition'][collection]
def find_one(self, json):
query = self.collection.find_one(json)
if query:
return query
else:
return None
def insert_one(self, json):
return self.collection.insert_one(json).inserted_id
def update_one(self, new_json, json):
new_values = { "$set": new_json }
return self.collection.update_one(json, new_values)