PHP8 MongoDB\Driver\Manager 類

2024-04-07 15:41 更新

(mongoDB >=1.0.0)

簡(jiǎn)介 

MongoDB\Driver\Manager 是主要入口點(diǎn) 到擴(kuò)展。它負(fù)責(zé)維護(hù)與 MongoDB 的連接 (無(wú)論是獨(dú)立服務(wù)器、副本集還是分片集群)。

實(shí)例化管理器時(shí)不會(huì)與 MongoDB 建立連接。 這意味著 MongoDB\Driver\Manager 始終可以 構(gòu)造,即使一個(gè)或多個(gè) MongoDB 服務(wù)器已關(guān)閉。

任何寫入或查詢都可能引發(fā)連接異常,因?yàn)檫B接是延遲創(chuàng)建的。 MongoDB 服務(wù)器也可能在腳本的生命周期內(nèi)變得不可用。 因此,必須將 Manager 上的所有操作都包裝在 try/catch 語(yǔ)句中。

類摘要

final class MongoDB\Driver\Manager {
/* 方法 */
final public addSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber): void
final public __construct(?string $uri = null, ?array $uriOptions = null, ?array $driverOptions = null)
final public createClientEncryption(array $options): MongoDB\Driver\ClientEncryption
final public executeBulkWrite(string $namespace, MongoDB\Driver\BulkWrite $bulk, array|MongoDB\Driver\WriteConcern|null $options = null): MongoDB\Driver\WriteResult
final public executeCommand(string $db, MongoDB\Driver\Command $command, array|MongoDB\Driver\ReadPreference|null $options = null): MongoDB\Driver\Cursor
final public executeQuery(string $namespace, MongoDB\Driver\Query $query, array|MongoDB\Driver\ReadPreference|null $options = null): MongoDB\Driver\Cursor
final public executeReadCommand(string $db, MongoDB\Driver\Command $command, ?array $options = null): MongoDB\Driver\Cursor
final public executeReadWriteCommand(string $db, MongoDB\Driver\Command $command, ?array $options = null): MongoDB\Driver\Cursor
final public executeWriteCommand(string $db, MongoDB\Driver\Command $command, ?array $options = null): MongoDB\Driver\Cursor
final public getEncryptedFieldsMap(): array|object|null
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 = null): MongoDB\Driver\Session
}

示例 

示例 #1 MongoDB\Driver\Manager::__construct() basic example

var_dump()ing MongoDB\Driver\Manager將打印出各種 有關(guān)經(jīng)理的詳細(xì)信息,否則通常不會(huì)公開。 這對(duì)于調(diào)試驅(qū)動(dòng)程序如何查看 MongoDB 設(shè)置以及 使用哪些選項(xiàng)。

<?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) {
  }
}


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)