在MongoDB shell中,如何列出当前使用的数据库的所有集合?


当前回答

用于切换到数据库。

By:

使用{your_database_name}示例:

use friends

其中friends是数据库的名称。

然后写下:

db.getCollectionNames()
show collections

这将为您提供集合的名称。

其他回答

首先,您需要使用数据库来显示其中的所有集合/表。

>show dbs
users 0.56787GB
test (empty)
>db.test.help() // this will give you all the function which can be used with this db
>use users
>show tables //will show all the collection in the db

Try:

help // To show all help methods
show dbs  // To show all dbs
use dbname  // To select your db
show collections // To show all collections in selected db

显示表

切换到数据库后,该命令通常在MongoDB shell上运行。

列出mongo shell中的所有集合:

db.getCollectionNames()显示表显示表格注意:集合将显示您所在的当前数据库目前

可以使用显示表或显示集合。