def query(request, collection, command, database=None): """ Main view to send commands to handler """ out = createBaseResponseObject() database = database or settings.MONGO_SERVER_DEFAULT_DB mongo = MongoWrapper() commandMethod = getattr(mongo, command, None) try: if not commandMethod or command not in mongo.available_commands: raise Exception("Command %s not supported. Available commands are: %s" % (command, ", ".join(mongo.available_commands))) mongo.connect() 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) results = commandMethod(database, collection, request) if results: out['results'] = results except Exception, e: out['errors'] = str(e) out['status'] = 0
def objects(request, collection, database=None): """ Main view to send commands to handler """ out = createBaseResponseObject() database = database or settings.MONGO_SERVER_DEFAULT_DB mongo = MongoWrapper() try: mongo.connect() 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_dict = getQueryDict(request) offset = getOffset(request) limit = getLimit(request) formatter = getFormatter(request) from formattersmanager import formattersManager formatters = formattersManager.getFormatters() if formatter and formatter not in formatters: raise Exception("Formatter %s is not available" % str(formatter)) if formatter: formatter_callback = formattersManager.getFormatter(formatter) else: formatter_callback = None query_result = mongo.objects(database, collection, query_dict=query_dict, offset=offset, limit=limit, formatter_callback=formatter_callback) records = query_result['records'] has_more = query_result['has_more'] out['results'] = records out['has_more'] = has_more except Exception, e: raise out['errors'] = str(e) out['status'] = 0
def dbMeta(request, database): mongo = MongoWrapper() try: out = createBaseResponseObject() mongo.connect() 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() out['results'] = existing_collections except Exception, e: out['errors'] = str(e) out['status'] = 0
def getDbInfo(database): mongo = MongoWrapper() try: out = createBaseResponseObject() mongo.connect() 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() #filtering out "system.indexes" collection existing_collections = [x for x in existing_collections if x != "system.indexes"] out['results'] = existing_collections except Exception, e: out['errors'] = str(e) out['status'] = 0
def getDbInfo(database): mongo = MongoWrapper() try: out = createBaseResponseObject() mongo.connect() 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() #filtering out "system.indexes" collection existing_collections = [ x for x in existing_collections if x != "system.indexes" ] out['results'] = existing_collections except Exception, e: out['errors'] = str(e) out['status'] = 0
def query(request, collection, command, database=None): """ Main view to send commands to handler """ out = createBaseResponseObject() database = database or settings.MONGO_SERVER_DEFAULT_DB mongo = MongoWrapper() commandMethod = getattr(mongo, command, None) try: if not commandMethod or command not in mongo.available_commands: raise Exception( "Command %s not supported. Available commands are: %s" % (command, ", ".join(mongo.available_commands))) mongo.connect() 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) results = commandMethod(database, collection, request) if results: out['results'] = results except Exception, e: out['errors'] = str(e) out['status'] = 0