The MongoDB\Driver\Manager class
(mongodb >=1.0.0)
Введение
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.
Обзор классов
$namespace
, MongoDB\Driver\BulkWrite $bulk
[, MongoDB\Driver\WriteConcern $writeConcern
] )$db
, MongoDB\Driver\Command $command
[, MongoDB\Driver\ReadPreference $readPreference
] )$namespace
, MongoDB\Driver\Query $query
[, MongoDB\Driver\ReadPreference $readPreference
] )Примеры
Пример #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);
?>
Результатом выполнения данного примера будет что-то подобное:
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 } }
Содержание
- 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::getServers — Return the servers to which this manager is connected
- MongoDB\Driver\Manager::selectServer — Select a server matching a read preference
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- MongoDB\Driver\Manager
- MongoDB\Driver\Command
- MongoDB\Driver\Query
- MongoDB\Driver\BulkWrite
- MongoDB\Driver\WriteConcern
- MongoDB\Driver\ReadPreference
- MongoDB\Driver\ReadConcern
- MongoDB\Driver\Cursor
- MongoDB\Driver\CursorId
- MongoDB\Driver\Server
- MongoDB\Driver\WriteConcernError
- MongoDB\Driver\WriteError
- MongoDB\Driver\WriteResult
Коментарии
According to Mongo, this (i.e., MongoDB\Driver\Manager) is an "entry point" for the extension:
"This class serves as an entry point for the MongoDB PHP Library. It is the preferred class for connecting to a MongoDB server or cluster of servers and acts as a gateway for accessing individual databases and collections. MongoDB\Client is analogous to the driver’s MongoDB\Driver\Manager class, which it composes."
copied from here: https://docs.mongodb.com/php-library/master/reference/class/MongoDBClient/
However, any comparison of the "mongodb" docs here on php.net versus the "mongodb driver" docs on mongo's site shows dramatic and ever-changing differences.