📜  列出 MongoDB shell 中的所有集合 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:36:51.187000             🧑  作者: Mango

列出 MongoDB shell 中的所有集合 - Shell-Bash

在 MongoDB shell 中,我们可以使用 show collections 命令来列出当前数据库中的所有集合。

用法示例
> use mydb
switched to db mydb
> db.createCollection('users')
{ "ok" : 1 }
> db.createCollection('posts')
{ "ok" : 1 }
> show collections
posts
users
结果说明

当我们在数据库中创建了集合后,使用 show collections 命令会列出所有的集合名,并按照字母顺序排列。

注意事项
  • show collections 命令只适用于当前数据库,如果需要列出其他数据库中的集合,需要先切换到对应的数据库。
  • 如果当前数据库中没有任何集合,则 show collections 命令不会输出任何内容。
总结

show collections 命令在 MongoDB shell 中非常便利,我们可以在不使用 GUI 的情况下快速了解当前数据库中的集合信息。