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


当前回答

> show dbs        
anuradhfirst  0.000GB
local         0.000GB
> use anuradhfirst
switched to db anuradhfirst
> show collections
record

使用mongo连接MongoDB数据库。这将启动连接。然后运行showdbs命令。这将显示所有退出/可用的数据库。然后选择所需的数据库。在上文中,它是第一个。然后运行use anuradhfirst。这将切换到所需的数据库。然后运行showcollections命令。这将显示所选数据库中的所有集合。

其他回答

如果有人使用Python和PyMongo:

db.list_collection_names()

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

>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

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

列出mongo shell中的所有集合:

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

使用mongo shell中的以下命令:

show collections