首页 文章

如何列出mongo shell中的所有数据库?

提问于
浏览
121

我知道如何list all collections in a particular database,但如何在MongoDB shell中列出所有可用的数据库?

5 回答

  • 42

    列出mongoDB控制台中的所有数据库都使用命令 show dbs .

    有关此内容的更多信息,请参阅可在mongo shell中使用的Mongo Shell Command Helpers .

  • 23

    对于MongoDB shell 3.0.5版,在shell中插入以下命令:

    db.adminCommand('listDatabases')
    

    或者:

    db.getMongo().getDBNames()
    
  • 0

    你也可以试试这个

    对于数据库列表---

    show databases
    show dbs
    

    对于表/收藏清单---

    show collections
    show tables
    db.getCollectionNames()
    

    希望这可以帮助..

  • 135

    从命令行问题

    mongo --quiet --eval  "printjson(db.adminCommand('listDatabases'))"
    

    它给出了输出

    {
        "databases" : [
            {
                "name" : "admin",
                "sizeOnDisk" : 978944,
                "empty" : false
            },
            {
                "name" : "local",
                "sizeOnDisk" : 77824,
                "empty" : false
            },
            {
                "name" : "meteor",
                "sizeOnDisk" : 778240,
                "empty" : false
            }
        ],
        "totalSize" : 1835008,
        "ok" : 1
    }
    
  • 36

    在shell上列出mongodb数据库

    show databases     //Print a list of all available databases.
     show dbs   // Print a list of all databases on the server.
    

    几个基本命令

    use <db>    // Switch current database to <db>. The mongo shell variable db is set to the current database.
    show collections    //Print a list of all collections for current database.
    show users  //Print a list of users for current database.
    show roles  //Print a list of all roles, both user-defined and built-in, for the current database.
    

相关问题