在MongoDB shell中,如何列出当前使用的数据库的所有集合?
当前回答
除了其他人建议的选项外:
show collections // Output every collection
show tables
db.getCollectionNames() // Shows all collections as a list
如果您想知道每个集合是如何创建的(例如,它是一个具有特定大小的上限集合),还有另一种方法非常方便:
db.system.namespaces.find()
其他回答
> show collections
将列出当前选定DB中的所有集合,如命令行帮助(help)中所述。
>显示表格
它给出了与卡梅伦的答案相同的结果。
使用mongo shell中的以下命令:
show collections
首先,您需要使用数据库来显示其中的所有集合/表。
>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
用于切换到数据库。
By:
使用{your_database_name}示例:
use friends
其中friends是数据库的名称。
然后写下:
db.getCollectionNames()
show collections
这将为您提供集合的名称。
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?