Exemplo n.º 1
0
def read_objects(collection_name, query={}, limit=0, offset=0, sort=settings.DEFAULT_SORT, *args, **kwargs):
    
    try:
        response = createResponse200()
        
        mongo = Mongo()
        mongo.connect()
        database = mongo.use_db(database_name)
            
        count = mongo.count(collection_name, query, limit=0, offset=0, sort=sort)
        found = mongo.find(collection_name, query, limit=limit, offset=offset, sort=sort)
        
        response['result']['total'] = count
        response['result']['has_more'] = True if limit + offset < count else False
        response['result']['objects'] = found
        response['result']['count'] = len(found)
        response['result']['limit'] = limit
        response['result']['offset'] = offset
        
        
    except Exception, e:
        response = createResponse401(str(e))
Exemplo n.º 2
0
def read_objects(collection_name,
                 query={},
                 limit=0,
                 offset=0,
                 sort=settings.DEFAULT_SORT,
                 *args,
                 **kwargs):

    try:
        response = createResponse200()

        mongo = Mongo()
        mongo.connect()
        database = mongo.use_db(database_name)

        count = mongo.count(collection_name,
                            query,
                            limit=0,
                            offset=0,
                            sort=sort)
        found = mongo.find(collection_name,
                           query,
                           limit=limit,
                           offset=offset,
                           sort=sort)

        response['result']['total'] = count
        response['result'][
            'has_more'] = True if limit + offset < count else False
        response['result']['objects'] = found
        response['result']['count'] = len(found)
        response['result']['limit'] = limit
        response['result']['offset'] = offset

    except Exception, e:
        response = createResponse401(str(e))
Exemplo n.º 3
0
 def test(self):
     mongo = Mongo()
     mongo.populate()
     things = mongo.count()
     self.failIf(things != 5)
 def test(self):
     mongo = Mongo()
     mongo.populate()
     things = mongo.count()
     self.failIf(things != 5)