函数名:MongoDB\Driver\ServerDescription::getType()
适用版本:MongoDB PHP扩展版本1.0.0以上
用法:该方法用于获取MongoDB服务器的类型。
语法:public function getType(): string
返回值:该方法返回一个字符串,表示MongoDB服务器的类型。可能的值包括:Unknown、Standalone、Mongos、RSPrimary、RSSecondary、RSArbiter、RSOther。
示例:
<?php
// 假设已经连接到MongoDB服务器
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// 获取服务器的描述信息
$servers = $manager->getServers();
foreach ($servers as $server) {
// 获取服务器类型
$type = $server->getType();
echo "服务器类型: " . $type . PHP_EOL;
}
?>
输出:
服务器类型: Standalone
注意事项: