3 from opnfv_testapi.common.config import CONF
5 DB = motor.MotorClient(CONF.mongo_url)[CONF.mongo_dbname]
8 def db_update(collection, query, update_req):
9 return _eval_db(collection, 'update', query, update_req, check_keys=False)
12 def db_delete(collection, query):
13 return _eval_db(collection, 'remove', query)
16 def db_aggregate(collection, pipelines):
17 return _eval_db(collection, 'aggregate', pipelines, allowDiskUse=True)
20 def db_list(collection, query):
21 return _eval_db(collection, 'find', query)
24 def db_save(collection, data):
25 return _eval_db(collection, 'insert', data, check_keys=False)
28 def db_find_one(collection, query):
29 return _eval_db(collection, 'find_one', query)
32 def _eval_db(collection, method, *args, **kwargs):
33 exec_collection = DB.__getattr__(collection)
34 return exec_collection.__getattribute__(method)(*args, **kwargs)
37 def _eval_db_find_one(query, table=None):
38 return _eval_db(table, 'find_one', query)