PHP Класс MongoClient

Наследование: use trait Alcaeus\MongoDbAdapter\Helper\ReadPreference, use trait Alcaeus\MongoDbAdapter\Helper\WriteConcern
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$boolean string
$connected boolean
$persistent boolean
$protocols array
$status string

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
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 )

Описание методов

__construct() публичный Метод

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() публичный Метод

Gets a database
public __get ( string $dbname ) : MongoDB
$dbname string - The database name.
Результат MongoDB - Returns a new db object.

__toString() публичный Метод

String representation of this connection
public __toString ( ) : string
Результат string - Returns hostname and port for this connection.

_getAuthenticationDatabase() публичный Метод

public _getAuthenticationDatabase ( ) : string
Результат string - The name of the database to authenticate

_getAuthenticationPassword() публичный Метод

public _getAuthenticationPassword ( ) : string
Результат string - The password for authentication

_getAuthenticationUsername() публичный Метод

public _getAuthenticationUsername ( ) : string
Результат string - The username for authentication

_getOption() публичный Метод

public _getOption ( string $name ) : string
$name string - The option name.
Результат string - The option value

_getReadProtocol() публичный Метод

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

_getWriteProtocol() публичный Метод

public _getWriteProtocol ( )

_validateReadPreference() публичный статический Метод

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

close() публичный Метод

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.
Результат boolean - Returns if the connection was successfully closed.

connect() публичный Метод

Connects to a database server or replica set
public connect ( ) : boolean
Результат boolean - If the connection was successful.

dropDB() публичный Метод

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.
Результат array - Returns the database response.

getConnections() публичный статический Метод

Return info about all open connections
public static getConnections ( ) : array
Результат array - An array of open connections.

getHosts() публичный Метод

Updates status for all associated hosts
public getHosts ( ) : array
Результат 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() публичный Метод

Get the read preference for this connection
public getReadPreference ( ) : array
Результат array -

killCursor() публичный Метод

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).
Результат 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() публичный Метод

Lists all of the databases available.
public listDBs ( ) : array
Результат 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() защищенный Метод

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
Результат array - In the form ['host' => $host, 'port' => $port, 'hash' => "$host:$port"]

purgeAllProtocols() защищенный Метод

Disconnect and remove all protocols/sockets
protected purgeAllProtocols ( )

purgeProtocols() защищенный Метод

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

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

selectCollection() публичный Метод

Gets a database collection
public selectCollection ( string $db, string $collection ) : MongoCollection
$db string - The database name.
$collection string - The collection name.
Результат MongoCollection - Returns a new collection object.

selectDB() публичный Метод

Gets a database
public selectDB ( string $name ) : MongoDB
$name string - The database name.
Результат MongoDB - Returns a new database object.

setReadPreference() публичный Метод

Set the read preference for this connection
public setReadPreference ( string $readPreference, array $tags = null ) : boolean
$readPreference string -
$tags array -
Результат boolean -

Описание свойств

$boolean публичное свойство

public string $boolean
Результат string

$connected публичное свойство

public bool $connected
Результат boolean

$persistent публичное свойство

public bool $persistent
Результат boolean

$protocols публичное свойство

public array $protocols
Результат array

$status публичное свойство

public string $status
Результат string