Mongo
class Mongo extends MongoClient (View source)
The connection point between MongoDB and PHP.
This class is used to initiate a connection and for database server commands.
Constants
VERSION |
|
DEFAULT_HOST |
|
DEFAULT_PORT |
|
RP_PRIMARY |
|
RP_PRIMARY_PREFERRED |
|
RP_SECONDARY |
|
RP_SECONDARY_PREFERRED |
|
RP_NEAREST |
|
Properties
$connected | from MongoClient | ||
$status | from MongoClient | ||
protected | $server | from MongoClient | |
protected | $persistent | from MongoClient |
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.
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)
Gets a database collection
(PECL mongo >= 1.3.0)
Set read preference
(PECL mongo >= 1.1.0)
Choose a new secondary for slaveOkay reads
(PECL mongo >= 1.2.0)
Get pool size for connection pools
(PECL mongo >= 1.1.0)
Returns the address being used by this for slaveOkay reads
(PECL mongo >= 1.1.0)
Get slaveOkay setting for this connection
Connects to paired database server
(PECL mongo >= 1.2.0)
Returns information about all connection pools.
(PECL mongo >= 1.1.0)
Change slaveOkay setting for this connection
(PECL mongo >= 1.2.0)
Set the size for future connection pools.
Creates a persistent connection with a database server
Creates a persistent connection with paired database servers
Connects with a database server
Check if there was an error on the most recent db operation performed
Checks for the last error thrown during a database operation
Clears any flagged errors on the connection
Creates a database error on the database.
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
int
getPoolSize()
(PECL mongo >= 1.2.0)
Get pool size for connection pools
bool
getSlave()
(PECL mongo >= 1.1.0)
Returns the address being used by this for slaveOkay reads
bool
getSlaveOkay()
(PECL mongo >= 1.1.0)
Get slaveOkay setting for this connection
bool
pairConnect()
Connects to paired database server
array
poolDebug()
(PECL mongo >= 1.2.0)
Returns information about all connection pools.
bool
setSlaveOkay(bool $ok)
(PECL mongo >= 1.1.0)
Change slaveOkay setting for this connection
bool
setPoolSize(int $size)
(PECL mongo >= 1.2.0)
Set the size for future connection pools.
bool
persistConnect(string $username = "", string $password = "")
Creates a persistent connection with a database server
bool
pairPersistConnect(string $username = "", string $password = "")
Creates a persistent connection with paired database servers
protected bool
connectUtil()
Connects with a database server
array|null
lastError()
Check if there was an error on the most recent db operation performed
array
prevError()
Checks for the last error thrown during a database operation
array
resetError()
Clears any flagged errors on the connection
bool
forceError()
Creates a database error on the database.