MongoDB教程10-MongoDB删除和重命名集合

删除集合操作

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

语法格式:

db.collection.drop()

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

> use myDB
switched to db myDB
>
> show collections
myColl
myColl2
myColl3
>
> db.myColl3.drop()    // 删除集合myColl3
true
>
> show collections    // 重新查看, 已删除myColl3
myColl
myColl2

重命名集合操作

使用 renamecollection() 方法可对集合进行重新命名

> show collections
myColl
myColl2
>
> db.myColl.renameCollection("myColl1")    // myColl -> myColl1
{ "ok" : 1 }
>
> show collections
myColl1
myColl2
posted @ 2020-09-02 16:15  KILLNPE  阅读(476)  评论(0编辑  收藏  举报