Moodle PHP Documentation 4.1
Moodle 4.1.11 (Build: 20240610) (c8c84b4af18)
MongoDB\Client Class Reference

Public Member Functions

 __construct (?string $uri=null, array $uriOptions=[], array $driverOptions=[])
 Constructs a new Client instance.
 
 __debugInfo ()
 Return internal properties for debugging purposes.
 
 __get (string $databaseName)
 Select a database.
 
 __toString ()
 Return the connection string (i.e.
 
 createClientEncryption (array $options)
 Returns a ClientEncryption instance for explicit encryption and decryption.
 
 dropDatabase (string $databaseName, array $options=[])
 Drop a database.
 
 getManager ()
 Return the Manager.
 
 getReadConcern ()
 Return the read concern for this client.
 
 getReadPreference ()
 Return the read preference for this client.
 
 getTypeMap ()
 Return the type map for this client.
 
 getWriteConcern ()
 Return the write concern for this client.
 
 listDatabaseNames (array $options=[])
 List database names.
 
 listDatabases (array $options=[])
 List databases.
 
 selectCollection (string $databaseName, string $collectionName, array $options=[])
 Select a collection.
 
 selectDatabase (string $databaseName, array $options=[])
 Select a database.
 
 startSession (array $options=[])
 Start a new client session.
 
 watch (array $pipeline=[], array $options=[])
 Create a change stream for watching changes to the cluster.
 

Public Attributes

const DEFAULT_URI = 'mongodb://127.0.0.1/'
 

Constructor & Destructor Documentation

◆ __construct()

MongoDB\Client::__construct ( ?string $uri = null,
array $uriOptions = [],
array $driverOptions = [] )

Constructs a new Client instance.

This is the preferred class for connecting to a MongoDB server or cluster of servers. It serves as a gateway for accessing individual databases and collections.

Supported driver-specific options:

  • typeMap (array): Default type map for cursors and BSON documents.

Other options are documented in MongoDB\Driver\Manager\__construct().

See also
https://mongodb.com/docs/manual/reference/connection-string/
https://php.net/manual/en/mongodb-driver-manager.construct.php
https://php.net/manual/en/mongodb.persistence.php#mongodb.persistence.typemaps
Parameters
string | null$uriMongoDB connection string. If none is provided, this defaults to self\DEFAULT_URI.
array$uriOptionsAdditional connection string options
array$driverOptionsDriver-specific options
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors
DriverInvalidArgumentExceptionfor parameter/option parsing errors in the driver
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

Member Function Documentation

◆ __debugInfo()

MongoDB\Client::__debugInfo ( )

Return internal properties for debugging purposes.

See also
https://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
Return values
array

◆ __get()

MongoDB\Client::__get ( string $databaseName)

Select a database.

Note: databases whose names contain special characters (e.g. "-") may be selected with complex syntax (e.g. $client->{"that-database"}) or selectDatabase().

See also
https://php.net/oop5.overloading#object.get
https://php.net/types.string#language.types.string.parsing.complex
Parameters
string$databaseNameName of the database to select
Return values
Database

◆ __toString()

MongoDB\Client::__toString ( )

Return the connection string (i.e.

URI).

Return values
string

◆ createClientEncryption()

MongoDB\Client::createClientEncryption ( array $options)

Returns a ClientEncryption instance for explicit encryption and decryption.

Parameters
array$optionsEncryption options
Return values
ClientEncryption

◆ dropDatabase()

MongoDB\Client::dropDatabase ( string $databaseName,
array $options = [] )

Drop a database.

See also
DropDatabase\__construct() for supported options
Parameters
string$databaseNameDatabase name
array$optionsAdditional options
Return values
array|objectCommand result document
Exceptions
UnsupportedExceptionif options are unsupported on the selected server
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ getManager()

MongoDB\Client::getManager ( )

Return the Manager.

Return values
Manager

◆ getReadConcern()

MongoDB\Client::getReadConcern ( )

Return the read concern for this client.

See also
https://php.net/manual/en/mongodb-driver-readconcern.isdefault.php
Return values
ReadConcern

◆ getReadPreference()

MongoDB\Client::getReadPreference ( )

Return the read preference for this client.

Return values
ReadPreference

◆ getTypeMap()

MongoDB\Client::getTypeMap ( )

Return the type map for this client.

Return values
array

◆ getWriteConcern()

MongoDB\Client::getWriteConcern ( )

Return the write concern for this client.

See also
https://php.net/manual/en/mongodb-driver-writeconcern.isdefault.php
Return values
WriteConcern

◆ listDatabaseNames()

MongoDB\Client::listDatabaseNames ( array $options = [])

List database names.

See also
ListDatabaseNames\__construct() for supported options
Exceptions
UnexpectedValueExceptionif the command response was malformed
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ listDatabases()

MongoDB\Client::listDatabases ( array $options = [])

List databases.

See also
ListDatabases\__construct() for supported options
Return values
DatabaseInfoIterator
Exceptions
UnexpectedValueExceptionif the command response was malformed
InvalidArgumentExceptionfor parameter/option parsing errors
DriverRuntimeExceptionfor other driver errors (e.g. connection errors)

◆ selectCollection()

MongoDB\Client::selectCollection ( string $databaseName,
string $collectionName,
array $options = [] )

Select a collection.

See also
Collection\__construct() for supported options
Parameters
string$databaseNameName of the database containing the collection
string$collectionNameName of the collection to select
array$optionsCollection constructor options
Return values
Collection
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

◆ selectDatabase()

MongoDB\Client::selectDatabase ( string $databaseName,
array $options = [] )

Select a database.

See also
Database\__construct() for supported options
Parameters
string$databaseNameName of the database to select
array$optionsDatabase constructor options
Return values
Database
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

◆ startSession()

MongoDB\Client::startSession ( array $options = [])

Start a new client session.

See also
https://php.net/manual/en/mongodb-driver-manager.startsession.php
Parameters
array$optionsSession options
Return values
Session

◆ watch()

MongoDB\Client::watch ( array $pipeline = [],
array $options = [] )

Create a change stream for watching changes to the cluster.

See also
Watch\__construct() for supported options
Parameters
array$pipelineList of pipeline operations
array$optionsCommand options
Return values
ChangeStream
Exceptions
InvalidArgumentExceptionfor parameter/option parsing errors

The documentation for this class was generated from the following file: