在MongoDB shell中,如何列出当前使用的数据库的所有集合?
当前回答
首先,您需要使用数据库来显示其中的所有集合/表。
>show dbs
users 0.56787GB
test (empty)
>db.test.help() // this will give you all the function which can be used with this db
>use users
>show tables //will show all the collection in the db
其他回答
使用mongo shell中的以下命令:
show collections
Try:
help // To show all help methods
show dbs // To show all dbs
use dbname // To select your db
show collections // To show all collections in selected db
> show collections
将列出当前选定DB中的所有集合,如命令行帮助(help)中所述。
> show dbs
anuradhfirst 0.000GB
local 0.000GB
> use anuradhfirst
switched to db anuradhfirst
> show collections
record
使用mongo连接MongoDB数据库。这将启动连接。然后运行showdbs命令。这将显示所有退出/可用的数据库。然后选择所需的数据库。在上文中,它是第一个。然后运行use anuradhfirst。这将切换到所需的数据库。然后运行showcollections命令。这将显示所选数据库中的所有集合。
你可以。。。
JavaScript(外壳):
db.getCollectionNames()
节点js:
db.listCollections()
非JavaScript(仅限shell):
show collections
我之所以称之为非JavaScript是因为:
$ mongo prodmongo/app --eval "show collections"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
2016-10-26T19:34:34.886-0400 E QUERY [thread1] SyntaxError: missing ; before statement @(shell eval):1:5
$ mongo prodmongo/app --eval "db.getCollectionNames()"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
[
"Profiles",
"Unit_Info"
]
如果你真的想得到甜蜜的节目集输出,你可以:
$ mongo prodmongo/app --eval "db.getCollectionNames().join('\n')"
MongoDB shell version: 3.2.10
connecting to: prodmongo/app
Profiles
Unit_Info
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?