- Reference >
- Database Commands >
- Administration Commands >
- listCollections
listCollections¶
On this page
New in version 3.0.0.
Definition¶
-
listCollections¶ Retrieve information, i.e. the name and options, about the collections in a database. Specifically, the command returns a document that contains information with which to create a cursor to the collection information. The
mongoshell provides thedb.getCollectionInfos()and thedb.getCollectionNames().The command has the following form:
The
listCollectionscommand can take the following optional field:Field Type Description filterdocument Optional. A query expression to filter the list of collections.
You can specify a query expression on the collection
nameand the collection options. For the available options, see Behavior.
Behavior¶
Use a filter to limit the results of listCollections. You
can specify a filter on the collection name and the following
collection options:
"options.capped""options.autoIndexId""options.size""options.max""options.flags""options.storageEngine"
The options correspond directly to the options available in
db.createCollection(), with the exception of the
"options.flags". The "options.flags" corresponds to the
usePowerOf2Sizes and the noPadding options in the
db.createCollection() method:
0corresponds tousePowerOf2Sizesflag set tofalseandnoPaddingflag set tofalse.1corresponds tousePowerOf2Sizesflag set totrueandnoPaddingflag set tofalse.2corresponds tousePowerOf2Sizesflag set tofalseandnoPaddingflag set totrue.3corresponds tousePowerOf2Sizesflag set totrueandnoPaddingflag set totrue.
Note
MongoDB 3.0 ignores the usePowerOf2Sizes flag.
See collMod and db.createCollection() for
more information.
For the descriptions on the options, see
db.createCollection().
Output¶
-
listCollections.cursor¶ A document that contains information with which to create a cursor to documents that contain collection names and options. The cursor information includes the cursor id, the full namespace for the command, as well as the first batch of results.
-
listCollections.ok¶ The return value for the command. A value of
1indicates success.
Example¶
List All Collections¶
The following example uses the db.getCollectionInfos() helper
to return information for all collections in the records database:
See also