mirror of
https://github.com/RobbieHan/sandboxMP.git
synced 2026-02-03 19:03:15 +08:00
18 lines
490 B
Python
18 lines
490 B
Python
import pymongo
|
|
|
|
|
|
class MongodbDriver(object):
|
|
|
|
def __init__(self, db='device', collection='change_compare'):
|
|
self.client = pymongo.MongoClient('127.0.0.1', 27017)
|
|
self.db = self.client[db]
|
|
self.col = self.db[collection]
|
|
|
|
def insert(self, content):
|
|
return self.col.insert(content)
|
|
|
|
def find(self, sort_by, **filters,):
|
|
data = self.col.find(filters)
|
|
if sort_by:
|
|
data.sort(sort_by, pymongo.DESCENDING)
|
|
return data |