class Database (View source)

Wrapper for the MongoDB class.

Properties

protected Connection $connection The Connection instance to which this database belongs.
protected EventManager $eventManager The EventManager used to dispatch events.
protected MongoDB $mongoDB The MongoDB instance being wrapped.
protected integer $numRetries Number of times to retry queries.

Methods

__construct(Connection $connection, MongoDB $mongoDB, EventManager $evm, boolean|integer $numRetries = 0)

Constructor.

array
authenticate(string $username, string $password)

Wrapper method for MongoDB::authenticate().

array
command(array $command, array $options = [], string $hash = null)

Wrapper method for MongoDB::command().

createCollection(string $name, boolean|array $cappedOrOptions = false, integer $size = 0, integer $max = 0)

Wrapper method for MongoDB::createCollection().

array
createDBRef(string $collection, mixed $a)

Wrapper method for MongoDB::createDBRef().

array
drop()

Wrapper method for MongoDB::drop().

array
dropCollection(string $coll)

Wrapper method for MongoDB::dropCollection().

array
execute($code, array $args = [])

Wrapper method for MongoDB::execute().

array
forceError() deprecated

Wrapper method for MongoDB::forceError().

getConnection()

Return the connection for this database.

array|null
getDBRef(array $reference)

Wrapper method for MongoDB::getDBRef().

getGridFS(string $prefix = 'fs')

Wrapper method for MongoDB::getGridFS().

MongoDB
getMongoDB()

Return the MongoDB instance being wrapped.

string
getName()

Return the name of this database.

integer
getProfilingLevel()

Wrapper method for MongoDB::getProfilingLevel().

integer
setProfilingLevel(integer $level)

Wrapper method for MongoDB::setProfilingLevel().

array
getReadPreference()

Wrapper method for MongoDB::getReadPreference().

boolean
setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoDB::setReadPreference().

boolean
getSlaveOkay()

Get whether secondary read queries are allowed for this database.

boolean
setSlaveOkay(boolean $ok = true)

Set whether secondary read queries are allowed for this database.

array
lastError()

Wrapper method for MongoDB::lastError().

array
listCollections()

Wrapper method for MongoDB::listCollections().

array
prevError() deprecated

Wrapper method for MongoDB::prevError().

array
repair(boolean $preserveClonedFiles = false, boolean $backupOriginalFiles = false)

Wrapper method for MongoDB::repair().

array
resetError() deprecated

Wrapper method for MongoDB::resetError().

selectCollection(string $name)

Wrapper method for MongoDB::selectCollection().

MongoCollection
__get(string $name)

Wrapper method for MongoDB::__get().

string
__toString()

Wrapper method for MongoDB::__toString().

array|null
doGetDBRef(array $reference)

Resolves a database reference.

doCreateCollection(string $name, array $options)

Creates a collection.

doGetGridFS(string $prefix)

Return a new GridFS instance.

doSelectCollection(string $name)

Return a new Collection instance.

mixed
retry(Closure $retry)

Conditionally retry a closure if it yields an exception.

array
convertSocketTimeout(array $options)

Convert "timeout" write option to "socketTimeoutMS" for driver version 1.5.0+.

Details

__construct(Connection $connection, MongoDB $mongoDB, EventManager $evm, boolean|integer $numRetries = 0)

Constructor.

Parameters

Connection $connection Connection to which this database belongs
MongoDB $mongoDB MongoDB instance being wrapped
EventManager $evm EventManager instance
boolean|integer $numRetries Number of times to retry queries

array authenticate(string $username, string $password)

Wrapper method for MongoDB::authenticate().

Parameters

string $username
string $password

Return Value

array

See also

http://php.net/manual/en/mongodb.authenticate.php

array command(array $command, array $options = [], string $hash = null)

Wrapper method for MongoDB::command().

Parameters

array $command Command document
array $options Client-side options (e.g. socket timeout)
string $hash Optional reference argument to collect the server hash for command cursors (for driver 1.5+ only)

Return Value

array

See also

http://php.net/manual/en/mongodb.command.php

Collection createCollection(string $name, boolean|array $cappedOrOptions = false, integer $size = 0, integer $max = 0)

Wrapper method for MongoDB::createCollection().

This method will dispatch preCreateCollection and postCreateCollection events.

Parameters

string $name Collection name
boolean|array $cappedOrOptions Capped collection indicator or an options array (for driver 1.4+)
integer $size Storage size for fixed collections (ignored if options array is used)
integer $max Max documents for fixed collections (ignored if options array is used)

Return Value

Collection

See also

http://php.net/manual/en/mongodb.createcollection.php

array createDBRef(string $collection, mixed $a)

Wrapper method for MongoDB::createDBRef().

Parameters

string $collection
mixed $a

Return Value

array

See also

http://php.net/manual/en/mongodb.createdbref.php

array drop()

Wrapper method for MongoDB::drop().

This method will dispatch preDropDatabase and postDropDatabase events.

Return Value

array

See also

http://php.net/manual/en/mongodb.drop.php

array dropCollection(string $coll)

Wrapper method for MongoDB::dropCollection().

Parameters

string $coll

Return Value

array

See also

http://php.net/manual/en/mongodb.dropcollection.php

array execute($code, array $args = [])

Wrapper method for MongoDB::execute().

Parameters

$code
array $args

Return Value

array

See also

http://php.net/manual/en/mongodb.execute.php

array forceError() deprecated

deprecated 1.1 Deprecated in driver; will be removed for 1.2

Wrapper method for MongoDB::forceError().

Connection getConnection()

Return the connection for this database.

Return Value

Connection

array|null getDBRef(array $reference)

Wrapper method for MongoDB::getDBRef().

This method will dispatch preGetDBRef and postGetDBRef events.

Parameters

array $reference

Return Value

array|null

See also

http://php.net/manual/en/mongodb.getdbref.php

GridFS getGridFS(string $prefix = 'fs')

Wrapper method for MongoDB::getGridFS().

This method will dispatch preGetGridFS and postGetGridFS events.

Parameters

string $prefix

Return Value

GridFS

See also

http://php.net/manual/en/mongodb.getgridfs.php

MongoDB getMongoDB()

Return the MongoDB instance being wrapped.

Return Value

MongoDB

string getName()

Return the name of this database.

Return Value

string

integer getProfilingLevel()

Wrapper method for MongoDB::getProfilingLevel().

integer setProfilingLevel(integer $level)

Wrapper method for MongoDB::setProfilingLevel().

Parameters

integer $level

Return Value

integer

See also

http://php.net/manual/en/mongodb.setprofilinglevel.php

array getReadPreference()

Wrapper method for MongoDB::getReadPreference().

For driver versions between 1.3.0 and 1.3.3, the return value will be converted for consistency with {@link Database::setReadPreference()}.

boolean setReadPreference(string $readPreference, array $tags = null)

Wrapper method for MongoDB::setReadPreference().

Parameters

string $readPreference
array $tags

Return Value

boolean

See also

http://php.net/manual/en/mongodb.setreadpreference.php

boolean getSlaveOkay()

Get whether secondary read queries are allowed for this database.

This method wraps getSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method considers any read preference other than PRIMARY as a true "slaveOkay" value.

boolean setSlaveOkay(boolean $ok = true)

Set whether secondary read queries are allowed for this database.

This method wraps setSlaveOkay() for driver versions before 1.3.0. For newer drivers, this method wraps setReadPreference() and specifies SECONDARY_PREFERRED.

Parameters

boolean $ok

Return Value

boolean Previous slaveOk value

See also

http://php.net/manual/en/mongodb.setreadpreference.php
http://php.net/manual/en/mongodb.setslaveokay.php

array lastError()

Wrapper method for MongoDB::lastError().

array listCollections()

Wrapper method for MongoDB::listCollections().

array prevError() deprecated

deprecated 1.1 Deprecated in driver; will be removed for 1.2

Wrapper method for MongoDB::prevError().

array repair(boolean $preserveClonedFiles = false, boolean $backupOriginalFiles = false)

Wrapper method for MongoDB::repair().

Parameters

boolean $preserveClonedFiles
boolean $backupOriginalFiles

Return Value

array

See also

http://php.net/manual/en/mongodb.repair.php

array resetError() deprecated

deprecated 1.1 Deprecated in driver; will be removed for 1.2

Wrapper method for MongoDB::resetError().

Collection selectCollection(string $name)

Wrapper method for MongoDB::selectCollection().

This method will dispatch preSelectCollection and postSelectCollection events.

Parameters

string $name

Return Value

Collection

See also

http://php.net/manual/en/mongodb.selectcollection.php

MongoCollection __get(string $name)

Wrapper method for MongoDB::__get().

Parameters

string $name

Return Value

MongoCollection

See also

http://php.net/manual/en/mongodb.get.php

string __toString()

Wrapper method for MongoDB::__toString().

protected array|null doGetDBRef(array $reference)

Resolves a database reference.

Parameters

array $reference

Return Value

array|null

See also

Database::getDBRef

protected Collection doCreateCollection(string $name, array $options)

Creates a collection.

Parameters

string $name
array $options

Return Value

Collection

See also

Database::createCollection

protected GridFS doGetGridFS(string $prefix)

Return a new GridFS instance.

Parameters

string $prefix

Return Value

GridFS

See also

Database::getGridFS

protected Collection doSelectCollection(string $name)

Return a new Collection instance.

Parameters

string $name

Return Value

Collection

See also

Database::selectCollection

protected mixed retry(Closure $retry)

Conditionally retry a closure if it yields an exception.

If the closure does not return successfully within the configured number of retries, its first exception will be thrown.

This method should not be used for write operations.

Parameters

Closure $retry

Return Value

mixed

protected array convertSocketTimeout(array $options)

Convert "timeout" write option to "socketTimeoutMS" for driver version 1.5.0+.

Parameters

array $options

Return Value

array