MongoDB\Driver\Manager 클래스

(mongodb >=1.0.0)


소개

MongoDB\Driver\Manager는 확장에 대한 기본 진입점입니다. MongoDB(독립형 서버, 복제본 세트 또는 샤딩된 클러스터)에 대한 연결을 유지 관리하는 역할을 합니다.

Manager를 인스턴스화하면 MongoDB에 연결되지 않습니다. 이는 하나 이상의 MongoDB 서버가 다운되더라도 MongoDB\Driver\Manager를 항상 구성할 수 있음을 의미합니다.

모든 쓰기 또는 쿼리는 연결이 느리게 생성되므로 연결 예외를 throw할 수 있습니다. MongoDB 서버는 스크립트 수명 동안 사용할 수 없게 될 수도 있습니다. 따라서 관리자의 모든 작업이 try/catch 문으로 래핑되어야 합니다.


클래스 개요

final class MongoDB\Driver\Manager {
  /* Methods */
  final public addSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber): void
  final public __construct(string $uri = "mongodb://127.0.0.1/", array $uriOptions = array(), array $driverOptions = array())
  final public createClientEncryption(array $options): MongoDB\Driver\ClientEncryption
  final public executeBulkWrite(string $namespace, MongoDB\Driver\BulkWrite $bulk, array $options = array()): MongoDB\Driver\WriteResult
  final public executeCommand(string $db, MongoDB\Driver\Command $command, array $options = array()): MongoDB\Driver\Cursor
  final public executeQuery(string $namespace, MongoDB\Driver\Query $query, array $options = array()): MongoDB\Driver\Cursor
  final public executeReadCommand(string $db, MongoDB\Driver\Command $command, array $options = array()): MongoDB\Driver\Cursor
  final public executeReadWriteCommand(string $db, MongoDB\Driver\Command $command, array $options = array()): MongoDB\Driver\Cursor
  final public executeWriteCommand(string $db, MongoDB\Driver\Command $command, array $options = array()): MongoDB\Driver\Cursor
  final public getReadConcern(): MongoDB\Driver\ReadConcern
  final public getReadPreference(): MongoDB\Driver\ReadPreference
  final public getServers(): array
  final public getWriteConcern(): MongoDB\Driver\WriteConcern
  final public removeSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber): void
  final public selectServer(?MongoDB\Driver\ReadPreference $readPreference = null): MongoDB\Driver\Server
  final public startSession(array $options = ?): MongoDB\Driver\Session
}
                

Examples

예제 #1 MongoDB\Driver\Manager::__construct() 기본 예제

MongoDB\Driver\Managervar_dump() 하면 일반적으로 노출되지 않는 관리자에 대한 다양한 세부 정보가 출력됩니다. 이것은 드라이버가 MongoDB 설정을 보는 방식과 사용되는 옵션을 디버그하는 데 유용할 수 있습니다.

                  
<?php

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

?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

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

목차