How to list all databases in the mongo shell?

前端 未结 7 1655
灰色年华
灰色年华 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:29

    I have found one solution, where admin()/others didn't worked.

    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()
    
    0 讨论(0)
提交回复
热议问题