You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
data-transport/transport/mongo.py

73 lines
2.4 KiB
Python

"""
Data Transport - 1.0
Steve L. Nyemba, The Phi Technology LLC
This file is a wrapper around mongodb for reading/writing content against a mongodb server and executing views (mapreduce)
"""
return p and q
class MongoReader(Mongo,Reader):
"""
This class will read from a mongodb data store and return the content of a document (not a collection)
"""
def __init__(self,**args):
Mongo.__init__(self,**args)
def read(self,size=-1):
collection = self.db[self.uid]
return collection.find({})
def view(self,**args):
"""
This function is designed to execute a view (map/reduce) operation
"""
pass
class MongoWriter(Mongo,Writer):
"""
This class is designed to write to a mongodb collection within a database
"""
def __init__(self,**args):
Mongo.__init__(self,**args)
def write(self,**args):
# document = self.db[self.uid].find()
collection = self.db[self.uid]
collection.update_one()
self.db[self.uid].insert_one(args['row'])
def set(self,document):
collection = self.db[self.uid]
if collection.count_document() > 0 :
collection.delete({_id:self.uid})
collecton.update_one({"_id":self.uid},document,True)