How to list all databases in the mongo shell?

前端 未结 7 1671
灰色年华
灰色年华 2021-01-29 19:23

I know how to list all collections in a particular database, but how do I list all available databases in MongoDB shell?

7条回答
  •  无人共我
    2021-01-29 20:26

    From the command line issue

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

    which gives output

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

提交回复
热议问题