在MongoDB shell中,如何列出当前使用的数据库的所有集合?
当前回答
> show collections
将列出当前选定DB中的所有集合,如命令行帮助(help)中所述。
其他回答
> show collections
将列出当前选定DB中的所有集合,如命令行帮助(help)中所述。
你可以。。。
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
显示表
切换到数据库后,该命令通常在MongoDB shell上运行。
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
1. show collections; // Display all collections
2. show tables // Display all collections
3. db.getCollectionNames(); // Return array of collection. Example :[ "orders", "system.profile" ]
每个集合的详细信息:
db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } )
对于具有所需访问权限(授予数据库listCollections操作的权限)的用户,该方法将列出数据库的所有集合的名称。对于没有所需访问权限的用户,该方法仅列出用户具有权限的集合。例如,如果用户在数据库中找到了特定集合,则该方法将仅返回该集合。
根据搜索字符串列出集合列表。
db.getCollectionNames().filter(function (CollectionName) { return /<Search String>/.test(CollectionName) })
示例:查找名称中包含“import”的所有集合
db.getCollectionNames().filter(function (CollectionName) { return /import/.test(CollectionName) })
推荐文章
- 如何排序mongodb与pymongo
- 如何在mongodb上导入。bson文件格式
- JSON文件的蒙古导入
- 如何删除mongodb中的数组元素?
- 修改MongoDB数据存储目录
- 在MongoDB中查找重复的记录
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 在猫鼬,我如何排序的日期?(node . js)
- 将映像存储在MongoDB数据库中
- 重复Mongo ObjectId的可能性在两个不同的集合中生成?
- Redis比mongoDB快多少?
- 无法连接到服务器127.0.0.1:27017
- 如何创建数据库的MongoDB转储?
- 如何将MongoDB作为Windows服务运行?
- 如何监听MongoDB集合的变化?