On this page
listCollections
On this page
New in version 3.0.0.
Definition
listCollections
-
Retrieve information, i.e. the name and options, about the collections and views in a database. Specifically, the command returns a document that contains information with which to create a cursor to the collection information. The
mongo
shell provides thedb.getCollectionInfos()
and thedb.getCollectionNames()
helper methods.The command has the following form:
{ listCollections: 1, filter: <document> }
The
listCollections
command can take the following optional field:Field Type Description filter
document Optional. A query expression to filter the list of collections.
You can specify a query expression on any of the fields returned by
listCollections
.
Behavior
Use a filter to limit the results of listCollections
. You can specify a filter
on any of the fields returned in the listCollections
result set.
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. Each document in the batch output contains the following fields:
Field Type Description name String Name of the collection. type String Type of data store. Returns collection
for collections andview
for views .options Document Collection options.
These options correspond directly to the options available in
db.createCollection()
, with the exception of the"options.flags"
. The"options.flags"
corresponds to theusePowerOf2Sizes
and thenoPadding
options in thedb.createCollection()
method:0
corresponds tousePowerOf2Sizes
flag set tofalse
andnoPadding
flag set tofalse
.1
corresponds tousePowerOf2Sizes
flag set totrue
andnoPadding
flag set tofalse
.2
corresponds tousePowerOf2Sizes
flag set tofalse
andnoPadding
flag set totrue
.3
corresponds tousePowerOf2Sizes
flag set totrue
andnoPadding
flag set totrue
.
Note
MongoDB 3.0 ignores the
usePowerOf2Sizes
flag. SeecollMod
anddb.createCollection()
for more information.For the descriptions on the options, see
db.createCollection()
.info Document Lists the following fields related to the collection:
- readOnly
-
boolean
. Iftrue
the data store is read only. - uuid
-
UUID. Once established, the collection UUID does not change. The collection UUID remains the same across replica set members and shards in a sharded cluster.
New in version 3.6.
idIndex Document Provides information on the _id
index for the collection.
Required Access
The user executing the command requires either find
privileges on the system.namespaces
collection or the listCollections
privilege action. At a minimum, the read
built-in role provide the requisite permissions.
Example
List All Collections
The following example uses the db.getCollectionInfos()
helper to return information for all collections in the records
database:
use records
db.getCollectionInfos();
See also