PHP 클래스 MongoClient

상속: use trait Alcaeus\MongoDbAdapter\Helper\ReadPreference, use trait Alcaeus\MongoDbAdapter\Helper\WriteConcern
파일 보기 프로젝트 열기: koubas/mongofill 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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