我知道如何列出一个特定的数据库中的所有集合,但我如何列出MongoDB shell中所有可用的数据库?
当前回答
对于MongoDB shell 3.0.5版本,在shell中插入以下命令:
db.adminCommand('listDatabases')
或者:
db.getMongo().getDBNames()
其他回答
使用show dbs命令列出mongoDB控制台中所有的数据库。
有关mongo shell命令的更多信息,请参阅mongo shell快速参考。
对于MongoDB shell 3.0.5版本,在shell中插入以下命令:
db.adminCommand('listDatabases')
或者:
db.getMongo().getDBNames()
数据库列表:
show databases
show dbs
表格/收藏列表:
show collections
show tables
db.getCollectionNames()
从命令行问题
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
}
要获得用于下游处理的所有数据库的垂直列表,请执行此操作
mongo --quiet --eval "printjson(db.adminCommand('listDatabases'))" | jq '.databases[].name' | tr -d '"'
哪个给出下面列出所有数据库的输出
admin
local
meteor
在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.
推荐文章
- HyperLogLog算法是如何工作的?
- 数据库和模式的区别
- 如何从命令行在windows中找到mysql数据目录
- 如何找到MySQL的根密码
- MongoDB:如何找到安装的MongoDB的确切版本
- 将表从一个数据库复制到另一个数据库的最简单方法?
- 如何使用mongoimport导入CSV文件?
- 什么是分片,为什么它很重要?
- 在mongodb中存储日期/时间的最佳方法
- 数据库触发器是必要的吗?
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- 为什么我应该使用基于文档的数据库而不是关系数据库?
- 哪个更快/最好?SELECT *或SELECT columnn1, colum2, column3等
- 将值从同一表中的一列复制到另一列