MongoDB 删除集合

MongoDB 教程 · 2019-03-05 20:56:43

本章节我们为大家介绍如何使用 MongoDB 来删除集合。

MongoDB 中使用 drop() 方法来删除集合。

语法格式:

db.collection.drop()

参数说明:

返回值

如果成功删除选定集合,则 drop() 方法返回 true,否则返回 false。

实例

在数据库 mydb 中,我们可以先通过 show collections 命令查看已存在的集合:

>use mydb
switched to db mydb
>show collections
mycol
mycol2
system.indexes
codercto
>

接着删除集合 mycol2 :

>db.mycol2.drop()
true
>

通过 show collections 再次查看数据库 mydb 中的集合:

>show collections
mycol
system.indexes
codercto
>

从结果中可以看出 mycol2 集合已被删除。

点击查看所有 MongoDB 教程 文章: https://www.codercto.com/courses/l/32.html

查看所有标签

The Art of Computer Programming, Volume 3

The Art of Computer Programming, Volume 3

Donald E. Knuth / Addison-Wesley Professional / 1998-05-04 / USD 74.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 3》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试