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


当前回答

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()显示表显示表格注意:集合将显示您所在的当前数据库目前

如果有人使用Python和PyMongo:

db.list_collection_names()

用于显示MongoDB数据库中所有集合的命令是

show collections

在运行show collections命令之前,必须选择数据库:

use mydb // mydb is the name of the database being selected

要查看所有数据库,可以使用以下命令

show dbs // Shows all the database names present

有关详细信息,请参阅入门。

对于使用WiredTiger存储引擎的MongoDB 3.0部署,如果从mongo shell的一个版本运行db.getCollectionNames()3.0之前的版本或3.0兼容版本之前的驱动程序版本,db.getCollectionNames()将不返回任何数据,即使存在现有集合。

有关详细信息,请参阅。