对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

MongoDB\Collection::drop()

MongoDB\Collection::drop()

删除该集合。

function drop(array $options = []): array|object
$options : array

指定所需选项的数组。

名称
类型
说明

comment

混合

使用户可以指定任意注释来帮助通过数据库分析器、currentOp 输出和日志来跟踪操作。

自 MongoDB 4.4 起此选项可用,如果为旧服务器版本指定,则会在执行时导致异常。

1.13版本新增。

加密字段

数组|对象

描述可查询加密的Queryable Encryption字段的文档。 如果省略,则会查阅autoEncryption驱动程序选项中的encryptedFieldsMap选项。 如果定义了encryptedFieldsMap但未指定此集合,则该库将最后一次尝试查询encryptedFields的服务器端值。 有关更多信息,请参阅 MongoDB 手册中的字段加密和可查询性。

此选项不会传递给drop命令。 该库使用它来确定除了加密集合之外还应删除的相关元数据集合。

1.13版本新增。

会话

与操作相关联的客户端会话。

1.3版本新增。

typeMap

阵列

应用游标的类型映射,决定如何将BSON文档转换为PHP值。默认为集合的类型映射。

这将用于返回的命令结果文档。

writeConcern

Write concern to use for the operation. Defaults to the collection's write concern.

无法将单个操作的写关注(write concern)指定为ACID 事务的一部分。相反,请在启动ACID 事务时设立writeConcern 选项。

An array or object with the result document of the drop command. The return type will depend on the typeMap option.

MongoDB\Exception\UnsupportedException,如果所选服务器使用了选项但不支持选项(例如collation、readConcern、writeConcern)。

MongoDB\Exception\InvalidArgumentException 用于与参数或选项解析相关的错误。

MongoDB\ 驱动程序\Exception\RuntimeException 用于扩展级别的其他错误(例如连接错误)。

以下操作会删除test数据库中的restaurantscollection:

<?php
$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)
}
}