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


当前回答

显示表

显示表格

or

db.getCollectionNames();

其他回答

> show collections

将列出当前选定DB中的所有集合,如命令行帮助(help)中所述。

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

有关详细信息,请参阅。

如果有人使用Python和PyMongo:

db.list_collection_names()

显示表

显示表格

or

db.getCollectionNames();

列出mongo shell中的所有集合:

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