コード例 #1
0
ファイル: engine.py プロジェクト: ericdill/amostra
 def get(self):
     database = self.settings['db']
     query = utils.unpack_params(self)
     num = query.pop("num", None)
     if num:
         try:
             docs = database.sample.find().sort('time', direction=pymongo.DESCENDING).limit(num)
         except pymongo.errors.PyMongoError:
             raise utils._compose_err_msg(500, '', query)
     else:
         try:
             docs = database.container.find(query).sort('time',
                                                     direction=pymongo.DESCENDING)
         except pymongo.errors.PyMongoError:
             raise utils._compose_err_msg(500, 'Query Failed: ', query)
     if docs:
         utils.return2client(self, docs)
     else:
         raise utils._compose_err_msg(500, 'No results found!')
コード例 #2
0
 def get(self):
     database = self.settings['db']
     query = utils.unpack_params(self)
     num = query.pop("num", None)
     if num:
         try:
             docs = database.sample.find().sort(
                 'time', direction=pymongo.DESCENDING).limit(num)
         except pymongo.errors.PyMongoError:
             raise utils._compose_err_msg(500, '', query)
     else:
         try:
             docs = database.container.find(query).sort(
                 'time', direction=pymongo.DESCENDING)
         except pymongo.errors.PyMongoError:
             raise utils._compose_err_msg(500, 'Query Failed: ', query)
     if docs:
         utils.return2client(self, docs)
     else:
         raise utils._compose_err_msg(500, 'No results found!')