Answers:
列出所有MongoDB中控制台中的数据库使用的命令show dbs。
有关此的更多信息,请参阅可在mongo shell中使用的Mongo Shell命令帮助器。
db显示当前数据库,test但此页面上未通过此命令列出,这在此进行了解释stackoverflow.com/q/38726310/73226
                    mongo在命令行中键入(因此mongo --nodb无法连接到数据库)获得shell的功能
                    show dbs因为当我进入文档时,我根本无法在show dbs任何地方找到该命令。“文档”有时可能非常令人沮丧。
                    --eval仅在交互式shell上不能在中运行。此答案的选项确实有效(尽管输出格式不同)stackoverflow.com/a/32192253/1837991
                    对于MongoDB Shell版本3.0.5,在Shell中插入以下命令:
db.adminCommand('listDatabases')或者:
db.getMongo().getDBNames()mongo admin --quiet -u <mongodb_admin> -p [<password>] --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})'hth
                    从命令行发出
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
}
在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.
我找到了一个解决方案,其中admin()/ others无法正常工作。
const { promisify } = require('util');
const exec = promisify(require('child_process').exec)
async function test() {
  var res = await exec('mongo  --eval "db.adminCommand( { listDatabases: 1 }         
)" --quiet')
  return { res }
}
test()
  .then(resp => {
    console.log('All dbs', JSON.parse(resp.res.stdout).databases)
  })
test()
show dbs在mongo控制台中,请在发布问题之前浏览mongodb标签wiki中的useful links部分,有时可能有助于您更快地找到解决方案。