On this page本页内容
db.collection.
drop
(<options>)¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Nodejs驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
Removes a collection or view from the database. 从数据库中删除集合或视图。The method also removes any indexes associated with the dropped collection. 该方法还会删除与删除的集合关联的所有索引。The method provides a wrapper around the 该方法为drop
command.drop
命令提供了一个包装器。
Note
For a sharded cluster, if you use 对于分片集群,如果使用db.collection.drop()
and then create a new collection with the same name, you must either:db.collection.drop()
然后创建同名的新集合,必须:
mongos
using flushRouterConfig
.flushRouterConfig
刷新每个mongos
上的缓存路由表。db.collection.remove()
to remove the existing documents and reuse the collection. db.collection.remove()
删除现有文档并重新使用集合。db.collection.drop()
has the form:其形式如下:
Changed in version 4.0.在版本4.0中更改。db.collection.drop()
accepts an options document.接受选项文档。
db.collection.drop()
takes an optional document with the following field:获取具有以下字段的可选文档:
writeConcern |
|
Returns: |
|
---|
db.collection.drop()
method and drop
command create an invalidate Event for any Change Streams opened on dropped collection.db.collection.drop()
方法和drop
命令为在删除的集合上打开的任何更改流创建一个invalidate
事件。db.collection.drop()
method and drop
command abort any in-progress index builds on the target collection before dropping the collection. db.collection.drop()
方法和drop
命令会在删除集合之前中止目标集合上任何正在生成的索引。For replica sets or shard replica sets, aborting an index on the primary does not simultaneously abort secondary index builds. 对于副本集或碎片副本集,中止主索引不会同时中止辅助索引生成。MongoDB attempts to abort the in-progress builds for the specified indexes on the primary and if successful creates an associated MongoDB尝试中止primary上指定索引的正在进行的构建,如果成功,则创建关联的abort
oplog entry. abort
oplog条目。Secondary members with replicated in-progress builds wait for a commit or abort oplog entry from the primary before either committing or aborting the index build.具有复制进行中生成的Secondary成员在提交或中止索引生成之前,会等待主成员的提交或中止oplog条目。
Changed in version 4.2.在版本4.2中更改。
db.collection.drop()
obtains an exclusive lock on the specified collection for the duration of the operation. db.collection.drop()
在操作期间获取指定集合的独占锁。All subsequent operations on the collection must wait until 集合上的所有后续操作都必须等到db.collection.drop()
releases the lock.db.collection.drop()
释放锁。
Prior to MongoDB 4.2, 在MongoDB 4.2之前,db.collection.drop()
obtained an exclusive lock on the parent database, blocking all operations on the database and all its collections until the operation completed.db.collection.drop()
获得了父数据库的独占锁,阻止了对数据库及其所有集合的所有操作,直到操作完成。
The following operation drops the 以下操作将删除当前数据库中的students
collection in the current database.students
集合。
w: "majority"
Write Concernw: "majority"
写关注点删除一个集合¶Changed in version 4.0:在版本4.0中更改:db.collection.drop()
accepts an options document.接受选项文档。
The following operation drops the 以下操作将删除当前数据库中的students
collection in the current database. students
集合。The operation uses the 该操作使用"majority"
write concern:"majority"
写入关注点: