def __init__(self, hostname='localhost', port=27017, database='test',
                 collection='system.profile'):
        """
        Constructor for ProfileCollection.

        Takes hostname, port, database and collection as parameters. All are
        optional and have default values.
        """
        # store parameters
        self.hostname = hostname
        self.port = port
        self.database = database
        self.collection = collection
        self.name = "%s.%s" % (database, collection)

        # property variables
        self._start = None
        self._end = None
        self._num_events = None

        self.cursor = None

        # test if database can be reached and collection exists
        try:
            mc = Connection(host=hostname, port=port)
            self.versions = [mc.server_info()[u'version']]
            binary = 'mongos' if mc.is_mongos else 'mongod'
            try:
                self.storage_engine = (mc[database].command('serverStatus')
                                       [u'storageEngine'][u'name'])
            except KeyError:
                self.storage_engine = 'mmapv1'

            self.binary = "%s (running on %s:%i)" % (binary, hostname, port)

        except (ConnectionFailure, AutoReconnect) as e:
            raise SystemExit("&s: Can't connect to database, please check if "
                             "a mongod instance is running on %s:%s."
                             % (e, hostname, port))

        self.coll_handle = mc[database][collection]

        if self.coll_handle.count() == 0:
            raise SystemExit("can't find any data in %s.%s collection. "
                             "Please check database and collection name."
                             % (database, collection))
def __init__ ( self , hostname = 'localhost' , port = 27017 , database = 'test' , collection = 'system.profile' ) : self . hostname = hostname self . port = port self . database = database self . collection = collection self . name = "%s.%s" % ( database , collection ) self . _start = None self . _end = None self . _num_events = None self . cursor = None try : mc = Connection ( host = hostname , port = port ) self . versions = [ mc . server_info ( ) [ u'version' ] ] binary = 'mongos' if mc . is_mongos else 'mongod' try : self . storage_engine = ( mc [ database ] . command ( 'serverStatus' ) [ u'storageEngine' ] [ u'name' ] ) except KeyError : self . storage_engine = 'mmapv1' self . binary = "%s (running on %s:%i)" % ( binary , hostname , port ) except ( ConnectionFailure , AutoReconnect ) as e : raise SystemExit ( "&s: Can't connect to database, please check if " "a mongod instance is running on %s:%s." % ( e , hostname , port ) ) self . coll_handle = mc [ database ] [ collection ] if self . coll_handle . count ( ) == 0 : raise SystemExit ( "can't find any data in %s.%s collection. " "Please check database and collection name." % ( database , collection ) )
Constructor for ProfileCollection.

        Takes hostname, port, database and collection as parameters. All are
        optional and have default values.