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


当前回答

>显示表格

它给出了与卡梅伦的答案相同的结果。

其他回答

使用mongo shell中的以下命令:

show collections

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

有关详细信息,请参阅。

> show collections

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

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

用于切换到数据库。

By:

使用{your_database_name}示例:

use friends

其中friends是数据库的名称。

然后写下:

db.getCollectionNames()
show collections

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