php8.5
Home/ Manual/ mongodb / driver/ The MongoDB\Driver\Manager class

The MongoDB\Driver\Manager class

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).

Intro

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.

Class synopsis

class MongoDB\Driver\Manager { }

Examples

MongoDB\Driver\Manager::__construct() basic example

var_dump()ing a MongoDB\Driver\Manager will print out various details about the manager that are otherwise not normally exposed. This can be useful to debug how the driver views your MongoDB setup, and which options are used.

php
<?php

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
var_dump($manager);

?>

The above example will output something similar to:

output
object(MongoDB\Driver\Manager)#1 (2) {
  ["uri"]=>
  string(26) "mongodb://127.0.0.1:27017/"
  ["cluster"]=>
  array(0) {
  }
}

Manager

In this section

MongoDB\Driver\Manager::__construct

Create new MongoDB Manager

MongoDB\Driver\Manager::addSubscriber

Registers a monitoring event subscriber with this Manager

MongoDB\Driver\Manager::createClientEncryption

Create a new ClientEncryption object

MongoDB\Driver\Manager::executeBulkWrite

Execute one or more write operations

MongoDB\Driver\Manager::executeBulkWriteCommand

Execute write operations using the bulkWrite command

MongoDB\Driver\Manager::executeCommand

Execute a database command

MongoDB\Driver\Manager::executeQuery

Execute a database query

MongoDB\Driver\Manager::executeReadCommand

Execute a database command that reads

MongoDB\Driver\Manager::executeReadWriteCommand

Execute a database command that reads and writes

MongoDB\Driver\Manager::executeWriteCommand

Execute a database command that writes

MongoDB\Driver\Manager::getEncryptedFieldsMap

Return the encryptedFieldsMap auto encryption option for the Manager

MongoDB\Driver\Manager::getReadConcern

Return the ReadConcern for the Manager

MongoDB\Driver\Manager::getReadPreference

Return the ReadPreference for the Manager

MongoDB\Driver\Manager::getServers

Return the servers to which this manager is connected

MongoDB\Driver\Manager::getWriteConcern

Return the WriteConcern for the Manager

MongoDB\Driver\Manager::removeSubscriber

Unregisters a monitoring event subscriber with this Manager

MongoDB\Driver\Manager::selectServer

Select a server matching a read preference

MongoDB\Driver\Manager::startSession

Start a new client session for use with this client

Source: reference/mongodb/mongodb/driver/manager.xml · from the official PHP manual (php/doc-en)