Database Manual / Reference / mongosh Methods / Connections

Mongo.getDBs() (mongosh method方法)

Description描述

Mongo.getDBs()

Returns information about all available databases. Mongo.getDBs() uses the listDatabases command.返回有关所有可用数据库的信息。Mongo.getDBs()使用listDatabases命令。

The Mongo.getDBs() method doesn't take any parameters.Mongo.getDBs()方法不接受任何参数。

Compatibility兼容性

This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Example示例

To list the available databases and metadata for the local MongoDB instance:要列出本地MongoDB实例的可用数据库和元数据,请执行以下操作:

db.getMongo().getDBs()

The db.getMongo() method returns the connection to the current MongoDB instance. The Mongo.getDBs() output resembles:db.getMongo()方法返回到当前MongoDB实例的连接。Mongo.getDBs()的输出类似于:

{
databases: [
{ name: 'admin', sizeOnDisk: Long("225280"), empty: false },
{ name: 'config', sizeOnDisk: Long("212992"), empty: false },
{ name: 'local', sizeOnDisk: Long("2400256"), empty: false },
{ name: 'test', sizeOnDisk: Long("303104"), empty: false }
],
totalSize: Long("3141632"),
totalSizeMb: Long("2"),
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1640186473, i: 1 }),
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
},
operationTime: Timestamp({ t: 1640186473, i: 1 })
}

The databases are listed in the highlighted lines.数据库列在突出显示的行中。