-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbmanager.py
More file actions
23 lines (18 loc) · 776 Bytes
/
Copy pathdbmanager.py
File metadata and controls
23 lines (18 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from pymongo.mongo_client import MongoClient
import pymongo
class DBManager():
def __init__(self,db,collection,address='127.0.0.1',port=27017,conn_string=None):
if conn_string is not None:
self.client=MongoClient(conn_string)
elif address is not None and port is not None:
self.client = MongoClient(address,port)
self.db = self.client[db]
self.collection = self.db[collection]
def save(self,dic):
self.collection.insert(dic)
def get_all(self):
return self.collection.find()
def get_max(self,attr):
return self.collection.find_one(sort=[(attr, pymongo.DESCENDING)])
def get_min(self,attr):
return self.collection.find_one(sort=[(attr, pymongo.ASCENDING)])