在MongoDB shell中,如何列出当前使用的数据库的所有集合?
当前回答
用于显示MongoDB数据库中所有集合的命令是
show collections
在运行show collections命令之前,必须选择数据库:
use mydb // mydb is the name of the database being selected
要查看所有数据库,可以使用以下命令
show dbs // Shows all the database names present
有关详细信息,请参阅入门。
其他回答
mongoshell上的以下命令是常见的。
show databases
show collections
而且
show dbs
use mydb
db.getCollectionNames()
有时,查看所有集合以及作为整体命名空间一部分的集合上的索引很有用:
以下是您的操作方法:
db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});
在这三个命令和这段代码之间,您应该很熟悉!
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
列出mongo shell中的所有集合:
db.getCollectionNames()显示表显示表格注意:集合将显示您所在的当前数据库目前
> show collections
将列出当前选定DB中的所有集合,如命令行帮助(help)中所述。
如果要显示MongoDB shell(命令行)中的所有集合,请使用shell助手,
show collections
显示当前数据库的所有集合。如果您想从应用程序中获取所有集合列表,那么可以使用MongoDB数据库方法
db.getCollectionNames()
有关MongoDB shell助手的更多信息,请参阅mongoShell快速参考。
推荐文章
- elasticsearch vs . MongoDB用于过滤应用程序
- MongoDB记录所有查询
- MongoDB:如何找到安装的MongoDB的确切版本
- 如何使用mongoimport导入CSV文件?
- 在mongodb中存储日期/时间的最佳方法
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?