MongoDB\Collection::drop()
定义
参数
$options
: array指定所需选项的数组。
名称类型描述注释mixedencryptedFieldsarray|object会话与操作关联的客户端会话。
新增在版本1.3.
typeMap数组应用于游标的 类型映射,它决定了 BSON 文档如何转换为 PHP 值。默认为集合的类型映射。
这将用于返回的命令结果文档。
writeConcern
返回值
一个包含 drop 命令结果文档的数组或对象。返回类型将取决于 typeMap
选项。
错误/异常
如果选项被使用但所选服务器不支持(例如 collation
、readConcern
、writeConcern
),将抛出 MongoDB\Exception\UnsupportedException
。
对于与参数或选项解析相关的错误,将抛出 MongoDB\Exception\InvalidArgumentException
。
对于扩展级别的其他错误(例如连接错误),将抛出 MongoDB\Driver\Exception\RuntimeException。
示例
以下操作将在 test
数据库中删除 restaurants
集合
$collection = (new MongoDB\Client)->test->restaurants; $result = $collection->drop(); var_dump($result);
输出结果将类似
object(MongoDB\Model\BSONDocument)#9 (1) { ["storage":"ArrayObject":private]=> array(3) { ["ns"]=> string(16) "test.restaurants" ["nIndexesWas"]=> int(3) ["ok"]=> float(1) } }
另请参阅
drop 命令参考 MongoDB 手册