PHP Class MongoClient

Inheritance: use trait Alcaeus\MongoDbAdapter\Helper\ReadPreference, use trait Alcaeus\MongoDbAdapter\Helper\WriteConcern
Afficher le fichier Open project: koubas/mongofill Class Usage Examples

Méthodes publiques

Свойство Type Description
$boolean string
$connected boolean
$persistent boolean
$protocols array
$status string

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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.

Private Methods

Méthode 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 )

Method Details

__construct() public méthode

Creates a new database connection object
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.

__get() public méthode

Gets a database
public __get ( string $dbname ) : MongoDB
$dbname string - The database name.
Résultat MongoDB - Returns a new db object.

__toString() public méthode

String representation of this connection
public __toString ( ) : string
Résultat string - Returns hostname and port for this connection.

_getAuthenticationDatabase() public méthode

public _getAuthenticationDatabase ( ) : string
Résultat string - The name of the database to authenticate

_getAuthenticationPassword() public méthode

public _getAuthenticationPassword ( ) : string
Résultat string - The password for authentication

_getAuthenticationUsername() public méthode

public _getAuthenticationUsername ( ) : string
Résultat string - The username for authentication

_getOption() public méthode

public _getOption ( string $name ) : string
$name string - The option name.
Résultat string - The option value

_getReadProtocol() public méthode

public _getReadProtocol ( array $readPreference = [] )
$readPreference array

_getWriteProtocol() public méthode

public _getWriteProtocol ( )

_validateReadPreference() public static méthode

public static _validateReadPreference ( $readPreference, array $tags = null )
$tags array

close() public méthode

Closes this connection
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.
Résultat boolean - Returns if the connection was successfully closed.

connect() public méthode

Connects to a database server or replica set
public connect ( ) : boolean
Résultat boolean - If the connection was successful.

dropDB() public méthode

Drops a database [deprecated]
public dropDB ( mixed $db ) : array
$db mixed - The database to drop. Can be a MongoDB object or the name of the database.
Résultat array - Returns the database response.

getConnections() public static méthode

Return info about all open connections
public static getConnections ( ) : array
Résultat array - An array of open connections.

getHosts() public méthode

Updates status for all associated hosts
public getHosts ( ) : array
Résultat 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.

getReadPreference() public méthode

Get the read preference for this connection
public getReadPreference ( ) : array
Résultat array -

killCursor() public méthode

Kills a specific cursor on the server
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).
Résultat 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.

listDBs() public méthode

Lists all of the databases available.
public listDBs ( ) : array
Résultat 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.

parseHostString() protected méthode

Given a host string, validate and parse it into hostname and port parts
protected parseHostString ( $host_str ) : array
$host_str string - The host:port string
Résultat array - In the form ['host' => $host, 'port' => $port, 'hash' => "$host:$port"]

purgeAllProtocols() protected méthode

Disconnect and remove all protocols/sockets
protected purgeAllProtocols ( )

purgeProtocols() protected méthode

Disconnect and remove given list of protocols
protected purgeProtocols ( array $protocols )
$protocols array - list of protocol objects to purge

retrieveReplSetHosts() protected méthode

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.
protected retrieveReplSetHosts ( )

selectCollection() public méthode

Gets a database collection
public selectCollection ( string $db, string $collection ) : MongoCollection
$db string - The database name.
$collection string - The collection name.
Résultat MongoCollection - Returns a new collection object.

selectDB() public méthode

Gets a database
public selectDB ( string $name ) : MongoDB
$name string - The database name.
Résultat MongoDB - Returns a new database object.

setReadPreference() public méthode

Set the read preference for this connection
public setReadPreference ( string $readPreference, array $tags = null ) : boolean
$readPreference string -
$tags array -
Résultat boolean -

Property Details

$boolean public_oe property

public string $boolean
Résultat string

$connected public_oe property

public bool $connected
Résultat boolean

$persistent public_oe property

public bool $persistent
Résultat boolean

$protocols public_oe property

public array $protocols
Résultat array

$status public_oe property

public string $status
Résultat string