Property | Type | Description | |
---|---|---|---|
$boolean | string | ||
$connected | boolean | ||
$persistent | boolean | ||
$protocols | array |
||
$status | string |
Method | Description | |
---|---|---|
__construct ( string $server = 'mongodb://localhost:27017', array $options = ['connect' => true] ) | Creates a new database connection object | |
__get ( string $dbname ) : MongoDB | Gets a database | |
__toString ( ) : string | String representation of this connection | |
_getAuthenticationDatabase ( ) : string | ||
_getAuthenticationPassword ( ) : string | ||
_getAuthenticationUsername ( ) : string | ||
_getOption ( string $name ) : string | ||
_getReadProtocol ( array $readPreference = [] ) | ||
_getWriteProtocol ( ) | ||
_validateReadPreference ( $readPreference, array $tags = null ) | ||
close ( boolean | string $connection = null ) : boolean | Closes this connection | |
connect ( ) : boolean | Connects to a database server or replica set | |
dropDB ( mixed $db ) : array | Drops a database [deprecated] | |
getConnections ( ) : array | Return info about all open connections | |
getHosts ( ) : array | Updates status for all associated hosts | |
getReadPreference ( ) : array | Get the read preference for this connection | |
killCursor ( string $serverHash, integer | mongoint64 $id ) : boolean | Kills a specific cursor on the server | |
listDBs ( ) : array | Lists all of the databases available. | |
selectCollection ( string $db, string $collection ) : MongoCollection | Gets a database collection | |
selectDB ( string $name ) : MongoDB | Gets a database | |
setReadPreference ( string $readPreference, array $tags = null ) : boolean | Set the read preference for this connection |
Method | Description | |
---|---|---|
parseHostString ( $host_str ) : array | Given a host string, validate and parse it into hostname and port parts | |
purgeAllProtocols ( ) | Disconnect and remove all protocols/sockets | |
purgeProtocols ( array $protocols ) | Disconnect and remove given list of protocols | |
retrieveReplSetHosts ( ) | For a replset, we need to connect to the first active host in our seed list and then ask the replset for its list of valid hosts. This list will be pre-filtered of any hidden members including arbiters. This is the host list we will use moving forward. |
Method | Description | |
---|---|---|
connectToFirstAvailableHost ( ) : Mongofill/Protocol | Iterates through configured hosts array attempting to connect to each. Returns as soon as a successful connection is made. If no connection can be established, throw an exception. | |
connectToHost ( $host, $port ) : Mongofill\Protocol | Establish a connection to specified host if not already connected to it | |
connectToReplSet ( ) | Attempts to connect to the MongoDB replSet and retrieve the replSet status, updating the host list with the proper host list from the replSet isMaster() command. | |
connectToReplSetPrimary ( ) : Mongofill/Protocol | Returns a connection the PRIMARY member of the current host list. | |
getNearestHostProtocol ( array $allowedServerTypes, array $readPreference ) : Mongofill\Protocol | Get a Protocol for the nearest candidate server matching the given types and read preference. This implements Member Selection as described here: http://docs.mongodb.org/manual/core/read-preference-mechanics/#replica-set-read-preference-behavior-member-selection | |
getReplSetInfo ( ) : array | Get an array with replica set config and status for the current PRIMARY. | |
pingHost ( $host, $port ) |
public __construct ( string $server = 'mongodb://localhost:27017', array $options = ['connect' => true] ) | ||
$server | string | - The server name. server should have the form: mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db |
$options | array | - An array of options for the connection. |
public __toString ( ) : string | ||
return | string | - Returns hostname and port for this connection. |
public _getAuthenticationDatabase ( ) : string | ||
return | string | - The name of the database to authenticate |
public _getAuthenticationPassword ( ) : string | ||
return | string | - The password for authentication |
public _getAuthenticationUsername ( ) : string | ||
return | string | - The username for authentication |
public _getOption ( string $name ) : string | ||
$name | string | - The option name. |
return | string | - The option value |
public _getReadProtocol ( array $readPreference = [] ) | ||
$readPreference | array |
public static _validateReadPreference ( $readPreference, array $tags = null ) | ||
$tags | array |
public close ( boolean | string $connection = null ) : boolean | ||
$connection | boolean | string | - If connection is not given, or FALSE then connection that would be selected for writes would be closed. In a single-node configuration, that is then the whole connection, but if you are connected to a replica set, close() will only close the connection to the primary server. |
return | boolean | - Returns if the connection was successfully closed. |
public static getConnections ( ) : array | ||
return | array | - An array of open connections. |
public getHosts ( ) : array | ||
return | array | - Returns an array of information about the hosts in the set. Includes each host's hostname, its health (1 is healthy), its state (1 is primary, 2 is secondary, 0 is anything else), the amount of time it took to ping the server, and when the last ping occurred. |
public getReadPreference ( ) : array | ||
return | array | - |
public killCursor ( string $serverHash, integer | mongoint64 $id ) : boolean | ||
$serverHash | string | - The server hash that has the cursor. This can be obtained through MongoCursor::info. |
$id | integer | mongoint64 | - The ID of the cursor to kill. You can either supply an int containing the 64 bit cursor ID, or an object of the MongoInt64 class. The latter is necessary on 32 bit platforms (and Windows). |
return | boolean | - Returns TRUE if the method attempted to kill a cursor, and FALSE if there was something wrong with the arguments (such as a wrong server_hash). The return status does not reflect where the cursor was actually killed as the server does not provide that information. |
public listDBs ( ) : array | ||
return | array | - Returns an associative array containing three fields. The first field is databases, which in turn contains an array. Each element of the array is an associative array corresponding to a database, giving th database's name, size, and if it's empty. The other two fields are totalSize (in bytes) and ok, which is 1 if this method ran successfully. |
protected parseHostString ( $host_str ) : array | ||
$host_str | string - The host:port string | |
return | array | - In the form ['host' => $host, 'port' => $port, 'hash' => "$host:$port"] |
protected purgeAllProtocols ( ) |
protected purgeProtocols ( array $protocols ) | ||
$protocols | array | - list of protocol objects to purge |
protected retrieveReplSetHosts ( ) |
public selectCollection ( string $db, string $collection ) : MongoCollection | ||
$db | string | - The database name. |
$collection | string | - The collection name. |
return | MongoCollection | - Returns a new collection object. |