final class Manager (View source)

The MongoDB\Driver\Manager is the main entry point to the extension. It is responsible for maintaining connections to MongoDB (be it standalone server, replica set, or sharded cluster).

No connection to MongoDB is made upon instantiating the Manager. This means the MongoDB\Driver\Manager can always be constructed, even though one or more MongoDB servers are down. Any write or query can throw connection exceptions as connections are created lazily. A MongoDB server may also become unavailable during the life time of the script. It is therefore important that all actions on the Manager to be wrapped in try/catch statements.

Methods

__construct(string|null $uri = null, array|null $uriOptions = null, array|null $driverOptions = null)

Manager constructor.

__wakeup()

No description

createClientEncryption(array $options)

Return a ClientEncryption instance.

executeBulkWrite(string $namespace, BulkWrite $bulk, WriteConcern|null $options = null)

Execute one or more write operations

executeCommand(string $db, Command $command, ReadPreference|null $options = null)

No description

executeQuery(string $namespace, Query $query, ReadPreference|null $options = null)

Execute a MongoDB query

executeReadCommand(string $db, Command $command, array|null $options = null)

No description

executeReadWriteCommand(string $db, Command $command, array|null $options = null)

No description

executeWriteCommand(string $db, Command $command, array|null $options = null)

No description

array|object|null
getEncryptedFieldsMap()

Return the encryptedFieldsMap auto encryption option for the Manager

getReadConcern()

Return the ReadConcern for the Manager

getReadPreference()

Return the ReadPreference for the Manager

array
getServers()

Return the servers to which this manager is connected

getWriteConcern()

Return the WriteConcern for the Manager

selectServer(ReadPreference|null $readPreference = null)

Preselect a MongoDB node based on provided readPreference. This can be useful to guarantee a command runs on a specific server when operating in a mixed version cluster.

startSession(array|null $options = null)

Start a new client session for use with this client

void
addSubscriber(Subscriber $subscriber)

Registers a monitoring event subscriber with this Manager

void
removeSubscriber(Subscriber $subscriber)

Unregisters a monitoring event subscriber with this Manager

Details

final __construct(string|null $uri = null, array|null $uriOptions = null, array|null $driverOptions = null)

Manager constructor.

Parameters

string|null $uri

A mongodb:// connection URI

array|null $uriOptions

Connection string options

array|null $driverOptions

Any driver-specific options not included in MongoDB connection spec.

Exceptions

InvalidArgumentException
RuntimeException

final __wakeup()

No description

final ClientEncryption createClientEncryption(array $options)

Return a ClientEncryption instance.

Parameters

array $options

Return Value

ClientEncryption

Exceptions

InvalidArgumentException
RuntimeException

final WriteResult executeBulkWrite(string $namespace, BulkWrite $bulk, WriteConcern|null $options = null)

Since: 1.4.0 added $options argument

Execute one or more write operations

Parameters

string $namespace

A fully qualified namespace (databaseName.collectionName)

BulkWrite $bulk

The MongoDB\Driver\BulkWrite to execute.

WriteConcern|null $options

WriteConcern type for backwards compatibility

Return Value

WriteResult

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
BulkWriteException
RuntimeException

final Cursor executeCommand(string $db, Command $command, ReadPreference|null $options = null)

Since: 1.4.0 added $options argument

No description

Parameters

string $db

The name of the database on which to execute the command.

Command $command

The command document.

ReadPreference|null $options

ReadPreference type for backwards compatibility

Return Value

Cursor

Exceptions

Exception
AuthenticationException
ConnectionException
RuntimeException
WriteException
WriteConcernException

final Cursor executeQuery(string $namespace, Query $query, ReadPreference|null $options = null)

Since: 1.4.0 added $options argument

Execute a MongoDB query

Parameters

string $namespace

A fully qualified namespace (databaseName.collectionName)

Query $query

A MongoDB\Driver\Query to execute.

ReadPreference|null $options

ReadPreference type for backwards compatibility

Return Value

Cursor

Exceptions

Exception
AuthenticationException
ConnectionException
RuntimeException

final Cursor executeReadCommand(string $db, Command $command, array|null $options = null)

Since: 1.4.0

No description

Parameters

string $db

The name of the database on which to execute the command that reads.

Command $command

The command document.

array|null $options

Return Value

Cursor

Exceptions

Exception
AuthenticationException
ConnectionException
RuntimeException
WriteException
WriteConcernException

final Cursor executeReadWriteCommand(string $db, Command $command, array|null $options = null)

Since: 1.4.0

No description

Parameters

string $db

The name of the database on which to execute the command that reads.

Command $command

The command document.

array|null $options

Return Value

Cursor

Exceptions

Exception
AuthenticationException
ConnectionException
RuntimeException
WriteException
WriteConcernException

final Cursor executeWriteCommand(string $db, Command $command, array|null $options = null)

Since: 1.4.0

No description

Parameters

string $db

The name of the database on which to execute the command that writes.

Command $command

The command document.

array|null $options

Return Value

Cursor

Exceptions

Exception
AuthenticationException
ConnectionException
RuntimeException
WriteException
WriteConcernException

final array|object|null getEncryptedFieldsMap()

Since: 1.14.0

Return the encryptedFieldsMap auto encryption option for the Manager

Return Value

array|object|null

final ReadConcern getReadConcern()

Return the ReadConcern for the Manager

Return Value

ReadConcern

Exceptions

InvalidArgumentException

final ReadPreference getReadPreference()

Return the ReadPreference for the Manager

Return Value

ReadPreference

Exceptions

InvalidArgumentException

final array getServers()

Return the servers to which this manager is connected

Return Value

array

Exceptions

InvalidArgumentException

final WriteConcern getWriteConcern()

Return the WriteConcern for the Manager

Return Value

WriteConcern

Exceptions

InvalidArgumentException

final Server selectServer(ReadPreference|null $readPreference = null)

Preselect a MongoDB node based on provided readPreference. This can be useful to guarantee a command runs on a specific server when operating in a mixed version cluster.

https://secure.php.net/manual/en/mongodb-driver-manager.selectserver.php

Parameters

ReadPreference|null $readPreference

Optionally, a MongoDB\Driver\ReadPreference to route the command to. If none given, defaults to the Read Preferences set by the MongoDB Connection URI.

Return Value

Server

Exceptions

InvalidArgumentException
ConnectionException
AuthenticationException
RuntimeException

final Session startSession(array|null $options = null)

Since: 1.4.0

Start a new client session for use with this client

Parameters

array|null $options

Return Value

Session

Exceptions

InvalidArgumentException
RuntimeException

final void addSubscriber(Subscriber $subscriber)

Since: 1.10.0

Registers a monitoring event subscriber with this Manager

Parameters

Subscriber $subscriber

Return Value

void

final void removeSubscriber(Subscriber $subscriber)

Since: 1.10.0

Unregisters a monitoring event subscriber with this Manager

Parameters

Subscriber $subscriber

Return Value

void