(mongodb >=1.0.0)
MongoDB\Driver\Manager::getServers — 傳回此管理器所連線的伺服器
傳回此管理器所連線的 MongoDB\Driver\Server 實例的 陣列。
注意:由於驅動程式會延遲連線到資料庫,因此如果在對 MongoDB\Driver\Manager 執行操作之前呼叫此方法,它可能會返回一個空的 陣列。
此函式沒有參數。
傳回此管理器所連線的 MongoDB\Driver\Server 實例的 陣列。
範例 #1 MongoDB\Driver\Manager::getServers() 範例
<?php
$manager = new MongoDB\Driver\Manager("mongodb://:27017");
/* 驅動程式會延遲連線到資料庫伺服器,因此 Manager::getServers()
* 最初可能會返回一個空陣列。 */
var_dump($manager->getServers());
$command = new MongoDB\Driver\Command(['ping' => 1]);
$manager->executeCommand('db', $command);
var_dump($manager->getServers());
?>上述範例將輸出類似以下內容
array(0) {
}
array(1) {
[0]=>
object(MongoDB\Driver\Server)#3 (10) {
["host"]=>
string(9) "localhost"
["port"]=>
int(27017)
["type"]=>
int(1)
["is_primary"]=>
bool(false)
["is_secondary"]=>
bool(false)
["is_arbiter"]=>
bool(false)
["is_hidden"]=>
bool(false)
["is_passive"]=>
bool(false)
["last_hello_response"]=>
array(8) {
["isWritablePrimary"]=>
bool(true)
["maxBsonObjectSize"]=>
int(16777216)
["maxMessageSizeBytes"]=>
int(48000000)
["maxWriteBatchSize"]=>
int(1000)
["localTime"]=>
object(MongoDB\BSON\UTCDateTime)#4 (1) {
["milliseconds"]=>
int(1447267964517)
}
["maxWireVersion"]=>
int(3)
["minWireVersion"]=>
int(0)
["ok"]=>
float(1)
}
["round_trip_time"]=>
int(554)
}
}