我知道如何列出一个特定的数据库中的所有集合,但我如何列出MongoDB shell中所有可用的数据库?
当前回答
在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.
其他回答
使用show dbs命令列出mongoDB控制台中所有的数据库。
有关mongo shell命令的更多信息,请参阅mongo shell快速参考。
对于MongoDB shell 3.0.5版本,在shell中插入以下命令:
db.adminCommand('listDatabases')
或者:
db.getMongo().getDBNames()
有几个命令列出MongoDB shell中的所有dbs。
首先,使用“mongo”命令启动Mongodb shell。
·
然后使用下列任意命令列出所有db。
show dbs 显示数据库 db。adminCommand({listDatabases: 1, nameOnly: true})
详情请点击这里
谢谢你!
数据库列表:
show databases
show dbs
表格/收藏列表:
show collections
show tables
db.getCollectionNames()
根据MongoDB官方文档,对于MongoDB 4+,只有运行db才能列出数据库名称。adminCommand({listDatabases: 1,, nameOnly: true})
如果您正在使用MongoDB Cloud,您需要首先连接到您的MongoDB部署。此时可以在终端执行命令mongosh "mongodb+srv://cluster0.<your-connection-string>.mongodb.net"——apiVersion 1——username <your-user-name>。
Atlas atlas-xxxxxx-shard-0 [primary] test> db.adminCommand({listDatabases:1 , nameOnly: true}) { databases: [ { name: 'sample_airbnb' }, { name: 'sample_analytics' }, { name: 'sample_geospatial' }, { name: 'sample_guides' }, { name: 'sample_mflix' }, { name: 'sample_restaurants' }, { name: 'sample_supplies' }, { name: 'sample_training' }, { name: 'sample_weatherdata' }, { name: 'admin' }, { name: 'local' } ], ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: xxxxxxxxxx, i: 1 }), signature: { hash: Binary(Buffer.from("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "hex"), 0), keyId: Long("xxxxxxxxxxxxx") } }, operationTime: Timestamp({ t: xxxxxxxxxx, i: 1 }) }
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- 获得PostgreSQL数据库中当前连接数的正确查询
- MySQL数据库表中的最大记录数
- 从现有模式生成表关系图(SQL Server)
- MongoDB记录所有查询
- HyperLogLog算法是如何工作的?
- 数据库和模式的区别
- 如何从命令行在windows中找到mysql数据目录
- 如何找到MySQL的根密码
- MongoDB:如何找到安装的MongoDB的确切版本
- 将表从一个数据库复制到另一个数据库的最简单方法?
- 如何使用mongoimport导入CSV文件?
- 什么是分片,为什么它很重要?
- 在mongodb中存储日期/时间的最佳方法
- 数据库触发器是必要的吗?