In the MongoDB shell, how do I list all collections for the current database that I'm using?
相关问题
- MongoDB can not create unique sparse index (duplic
- Spring Data MongoDB - lazy access to some fields
- Golang mongodb aggregation
- How to convert from Timestamp to Mongo ObjectID
- MongoDB Indexing: Multiple single-field vs single
相关文章
- mongodb有没有什么办法禁止读取数据的时候进行缓存
- mongodb-aggregate聚合查询分组后如何获得多字段
- mongodb error: how do I make sure that your journa
- How to track MongoDB requests from a console appli
- MongoError: cannot infer query fields to set, path
- Pymongo $in Query Not Working
- django.core.exceptions.ImproperlyConfigured: '
- How to represent an array with mixed types
I use
listCollections
(supports mongo 3.0 and up) for this purpose.example:
To fetch more info like index of the collection:
To print just the collection names:
I feel this provide more flexibility.
read more: https://docs.mongodb.com/manual/reference/command/listCollections/
3 Methods
show collections
show tables
db.getCollectionNames()
To list all databases:
To enter or use given database:
To list all collections:
Output:
(or)
Output:
(or)
Output:
To enter or use given collection
will list all the collections in the currently selected DB, as stated in the command line help (
help
).> show tables
It gives the same result as Cameron's answer.
Apart from the options suggested by other people:
There is also another way which can be really handy if you want to know how each of the collections was created (for example it is a capped collection with a particular size)
mongo
, this will start the connection.show dbs
command, this will show you all exiting/available database.database
you want.in above it isanuradhfirst
, then runuse anuradhfirst
.this will switch to the database you want.show collections
command, this will show all thecollections
inside your selected database.