MongoClient
class MongoClient (View source)
A connection between PHP and MongoDB. This class is used to create and manage connections See MongoClient::__construct() and the section on connecting for more information about creating connections.
Constants
VERSION |
|
DEFAULT_HOST |
|
DEFAULT_PORT |
|
RP_PRIMARY |
|
RP_PRIMARY_PREFERRED |
|
RP_SECONDARY |
|
RP_SECONDARY_PREFERRED |
|
RP_NEAREST |
|
Properties
$connected | |||
$status | |||
protected | $server | ||
protected | $persistent |
Methods
Creates a new database connection object
(PECL mongo >= 1.3.0)
Closes this database connection
This method does not need to be called, except in unusual circumstances.
Connects to a database server
Drops a database
Get connections Returns an array of all open connections, and information about each of the servers
Get hosts This method is only useful with a connection to a replica set. It returns the status of all of the hosts in the set. Without a replica set, it will just return an array with one element containing the host that you are connected to.
Get read preference Get the read preference for this connection
(PECL mongo >= 1.5.0)
Get the write concern for this connection
(PECL mongo >= 1.3.0)
Lists all of the databases available
(PECL mongo >= 1.3.0)
Gets a database collection
(PECL mongo >= 1.3.0)
Set read preference
(PECL mongo >= 1.1.0)
Choose a new secondary for slaveOkay reads
String representation of this connection
Details
__construct(string $server = "mongodb://localhost:27017", array $options = ["connect" => true], array $driver_options)
Creates a new database connection object
bool
close(bool|string $connection)
(PECL mongo >= 1.3.0)
Closes this database connection
This method does not need to be called, except in unusual circumstances.
The driver will cleanly close the database connection when the Mongo object goes out of scope.
bool
connect()
Connects to a database server
array
dropDB(mixed $db)
Drops a database
MongoDB
__get(string $dbname)
(PECL mongo >= 1.3.0)
Gets a database
static array
getConnections()
Get connections Returns an array of all open connections, and information about each of the servers
array
getHosts()
Get hosts This method is only useful with a connection to a replica set. It returns the status of all of the hosts in the set. Without a replica set, it will just return an array with one element containing the host that you are connected to.
array
getReadPreference()
Get read preference Get the read preference for this connection
array
getWriteConcern()
(PECL mongo >= 1.5.0)
Get the write concern for this connection
killCursor(string $server_hash, int|MongoInt64 $id)
Kills a specific cursor on the server
array
listDBs()
(PECL mongo >= 1.3.0)
Lists all of the databases available
MongoCollection
selectCollection(string $db, string $collection)
(PECL mongo >= 1.3.0)
Gets a database collection
MongoDB
selectDB(string $name)
(PECL mongo >= 1.3.0)
Gets a database
bool
setReadPreference(string $readPreference, array $tags = null)
(PECL mongo >= 1.3.0)
Set read preference
string
switchSlave()
(PECL mongo >= 1.1.0)
Choose a new secondary for slaveOkay reads
string
__toString()
String representation of this connection