Esempio n. 1
0
def dropObsoleteMongoResults():

    out = []
    qset = CollectionReference.objects.all()
    referenced = [obj.collection_name for obj in qset]
    
    from sketch.mongowrapper import mongo, default_mongo_db
    collections = mongo.getDb(default_mongo_db).collection_names()
    for coll in collections:
        if coll.startswith("results"):
            if coll not in referenced:
                out.append(coll)
                mongo.dropCollection(default_mongo_db, coll)
                
    return out
Esempio n. 2
0
     
     try:
         offset = int(options['offset'])        
     except:
         offset = 0
     
     
     out = sketch.helpers.createBaseResponseObject()
 
     try:
     
         existing_dbs = mongo.connection.database_names()
         if database not in existing_dbs:
             raise Exception("Database %s does not exist" % database)
             
         database_object = mongo.getDb(database)
         existing_collections = database_object.collection_names()
         if collection not in existing_collections:
             raise Exception("Collection %s does not exist" % collection)
         
         
         query_result = mongo.objects(database, collection, query_dict=query_dict, offset=offset, limit=limit, 
                                      formatter_callback=formatter_callback)
          
         out.update(query_result)
     
     except Exception, e:
         out['errors'] = str(e)
         out['status'] = 0
     
     print out