
- PHP & MongoDB 教程
- PHP & MongoDB - 首頁
- PHP & MongoDB - 概述
- PHP & MongoDB - 環境設定
- PHP & MongoDB 示例
- PHP & MongoDB - 連線資料庫
- PHP & MongoDB - 顯示資料庫
- PHP & MongoDB - 刪除資料庫
- PHP & MongoDB - 建立集合
- PHP & MongoDB - 刪除集合
- PHP & MongoDB - 顯示集合
- PHP & MongoDB - 插入文件
- PHP & MongoDB - 選擇文件
- PHP & MongoDB - 更新文件
- PHP & MongoDB - 刪除文件
- PHP & MongoDB - 嵌入式文件
- PHP & MongoDB - 錯誤處理
- PHP & MongoDB - 限制記錄
- PHP & MongoDB - 排序記錄
- PHP & MongoDB 有用資源
- PHP & MongoDB - 快速指南
- PHP & MongoDB - 有用資源
- PHP & MongoDB - 討論
PHP & MongoDB - 刪除集合
執行任何操作的第一步都是建立一個 Manager 例項。
// Connect to MongoDB using Manager Instance $manager = new MongoDB\Driver\Manager("mongodb://:27017");
第二步是準備並執行一條用於刪除集合的命令。
// Create a Command Instance $createCollection = new MongoDB\Driver\Command(["drop" => "sampleCollection"]); // Execute the command on the database $cursor = $manager->executeCommand("myDb", $createCollection);
示例
嘗試以下示例以在 MongoDB 伺服器中刪除一個集合 -
複製並貼上以下示例作為 mongodb_example.php -
<?php try { // connect to mongodb $manager = new MongoDB\Driver\Manager("mongodb://:27017"); // Create a Command Instance $dropCollection = new MongoDB\Driver\Command(["drop" => "sampleCollection"]); // Execute the command on the database $cursor = $manager->executeCommand("myDb", $dropCollection); echo "Collection dropped." } catch (MongoDB\Driver\Exception\Exception $e) { echo "Exception:", $e->getMessage(), "\n"; } ?>
輸出
訪問部署在 apache Web 伺服器上的 mongodb_example.php 並驗證輸出。
Collection dropped.
廣告