在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

其他回答

如何列出当前使用的数据库的所有集合?

三种方法

显示表显示表格db.getCollectionNames()


要列出所有数据库:

show dbs

要输入或使用给定数据库:

use databasename

要列出所有集合:

show collections

输出:

集合1集合2系统索引

(or)

show tables

输出:

集合1集合2系统索引

(or)

db.getCollectionNames()

输出:

[“collection1”,“collection2”,“system.indexs”]


输入或使用给定集合

use collectionname

如果有人使用Python和PyMongo:

db.list_collection_names()

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

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

有关详细信息,请参阅。

显示表

显示表格

or

db.getCollectionNames();