MongoDB删除

9个月前 (04-27)
在 MongoDB 中,可以使用 drop() 方法来从数据库中删除指定,它会从数据库中完全删除一个,并且不会留下与已删除关联的任何索引。

drop() 方法在使用时不需要带有任何参数,并且在使用参数调用时会产生错误,该方法的语法格式如下:

db.collection_name.drop()

其中 collection_name 为要删除的名称,方法调用成功会返回 true,否则返回 false。

【示例】查看数据库“bianchengbang”中的所有,并删除其中的“mycol”。

> show tables

mycol

user

website

> db.mycol.drop()

true

此“mycol”就成功删除了,您可以再次使用 show tables 令来查看数据库中的。

> show tables

user

website