The MongoDB\Driver\Manager class
(mongodb >=1.0.0)
Introduction
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
$uri
= "mongodb://127.0.0.1/"
[, array $uriOptions
= array()
[, array $driverOptions
= array()
]]] )$namespace
, MongoDB\Driver\BulkWrite $bulk
[, array $options
= array()
] ) : MongoDB\Driver\WriteResult$db
, MongoDB\Driver\Command $command
[, array $options
= array()
] ) : MongoDB\Driver\Cursor$namespace
, MongoDB\Driver\Query $query
[, array $options
= array()
] ) : MongoDB\Driver\Cursor$db
, MongoDB\Driver\Command $command
[, array $options
= array()
] ) : MongoDB\Driver\Cursor$db
, MongoDB\Driver\Command $command
[, array $options
= array()
] ) : MongoDB\Driver\Cursor$db
, MongoDB\Driver\Command $command
[, array $options
= array()
] ) : MongoDB\Driver\CursorExamples
Example #1 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
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
var_dump($manager);
?>
The above example will output something similar to:
object(MongoDB\Driver\Manager)#1 (3) { ["request_id"]=> int(1714636915) ["uri"]=> string(25) "mongodb://localhost:27017" ["cluster"]=> array(13) { ["mode"]=> string(6) "direct" ["state"]=> string(4) "born" ["request_id"]=> int(0) ["sockettimeoutms"]=> int(300000) ["last_reconnect"]=> int(0) ["uri"]=> string(25) "mongodb://localhost:27017" ["requires_auth"]=> int(0) ["nodes"]=> array(...) ["max_bson_size"]=> int(16777216) ["max_msg_size"]=> int(50331648) ["sec_latency_ms"]=> int(15) ["peers"]=> array(0) { } ["replSet"]=> NULL } }
Table of Contents
- MongoDB\Driver\Manager::__construct — Create new MongoDB Manager
- MongoDB\Driver\Manager::executeBulkWrite — Execute one or more write operations
- 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::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::selectServer — Select a server matching a read preference
- MongoDB\Driver\Manager::startSession — Start a new client session for use with this client
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-class.mongodb-driver-manager.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.