(mongodb >=1.10.0)
MongoDB\Driver\ServerApi::V1
伺服器 API 版本 1。
範例 #1 在管理器上宣告 API 版本
<?php
以上範例將輸出
4.9.0-alpha7-49-gb968ca0
範例 #2 在管理器上宣告嚴格的 API 版本
以下範例設定了 strict
旗標,它會告知伺服器拒絕任何不屬於已宣告 API 版本的指令。這將導致在執行 buildInfo 指令時發生錯誤。
<?php
use MongoDB\Driver\Manager;
use MongoDB\Driver\ServerApi;
$v1 = new ServerApi(ServerApi::v1, true);
$manager = new Manager('mongodb://127.0.0.1:27017', [], ['serverApi' => $v1]);
$command = new MongoDB\Driver\Command(['buildInfo' => 1]);
try {
$cursor = $manager->executeCommand('admin', $command);
} catch(MongoDB\Driver\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
/* buildInfo 指令會回傳單一結果文件,因此我們需要存取
* 游標中的第一個結果。 */
$buildInfo = $cursor->toArray()[0];
echo $buildInfo->version, "\n";
?>
以上範例將輸出
Provided apiStrict:true, but the command buildInfo is not in API Version 1