aboutsummaryrefslogtreecommitdiff
path: root/umosapi/app_db/uobject.py
diff options
context:
space:
mode:
Diffstat (limited to 'umosapi/app_db/uobject.py')
-rw-r--r--umosapi/app_db/uobject.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/umosapi/app_db/uobject.py b/umosapi/app_db/uobject.py
index cffd9ba..5d282a5 100644
--- a/umosapi/app_db/uobject.py
+++ b/umosapi/app_db/uobject.py
@@ -9,12 +9,12 @@ class UObject(object):
def __init__(self, app=None):
self.app = app
- def all(self):
+ def all(self, collections):
db = MongoDB(self.app)
mongo = db.connection()
- return list(mongo.db.uobjects.find({}))
+ return list(mongo.db[collections].find({}))
- def register(self, datas):
+ def register(self, collections, datas):
db = MongoDB(self.app)
mongo = db.connection()
@@ -24,10 +24,10 @@ class UObject(object):
}
return error, 400
- _id = mongo.db.uobjects.insert({"datas": datas})
+ _id = mongo.db[collections].insert({"datas": datas})
return {"_id": str(_id)}
- def remove(self, _id):
+ def remove(self, collections, _id):
db = MongoDB(self.app)
mongo = db.connection()
@@ -36,20 +36,20 @@ class UObject(object):
"msg": "UObject _id is must match following regex [0-9a-z]{24}"
}
return error, 400
- if len(list(mongo.db.uobjects.find({"_id": ObjectId(_id)}))) == 0:
+ if len(list(mongo.db[collections].find({"_id": ObjectId(_id)}))) == 0:
return '', 404
- mongo.db.uobjects.remove({"_id": ObjectId(_id)})
+ mongo.db[collections].remove({"_id": ObjectId(_id)})
return {"_id": _id}, 200
- def update(self, _id, datas):
+ def update(self, collections, _id, datas):
db = MongoDB(self.app)
mongo = db.connection()
if not _id:
error = {"msg": "UObject _id is required"}
return error, 400
- elif len(list(mongo.db.uobjects.find({"_id": ObjectId(_id)}))) == 0:
+ elif len(list(mongo.db[collections].find({"_id": ObjectId(_id)}))) == 0:
error = {
"msg": "UObject {} does not exist.".format(_id)
}
@@ -58,21 +58,21 @@ class UObject(object):
datas = dict(
("datas.{}".format(key), value) for (key, value) in datas.items()
)
- mongo.db.uobjects.update_one(
+ mongo.db[collections].update_one(
{"_id": ObjectId(_id)}, {"$set": datas}
)
return {"msg": "UObject updated.", "_id": _id}
- def eq(self, key, value):
+ def eq(self, collections, key, value):
db = MongoDB(self.app)
mongo = db.connection()
- return list(mongo.db.uobjects.find(
+ return list(mongo.db[collections].find(
{"datas.{}".format(key): {"$eq": value}}
))
- def reset(self):
+ def reset(self, collections):
db = MongoDB(self.app)
mongo = db.connection()
- mongo.db.uobjects.remove()
+ mongo.db[collections].remove()
return "done"