Access the mongo Shell Help
In addition to the documentation in the MongoDB Manual, the mongo
shell provides some additionalinformation in its “online” help system. This document provides anoverview of accessing this help information.
Command Line Help
To see the list of options and help for starting the mongo
shell, use the —help
option from the command line:
- mongo --help
Shell Help
To see the list of help, in the mongo
shell, type help
:
- help
Database Help
In the mongo
shell:
- To see the list of databases on the server, use the
show dbs
command: [1]
- show dbs
show databases
is an alias for show dbs
.
- To see the list of help for methods you can use on the
db
object, call thedb.help()
method:
- db.help()
- To see the implementation of a method in the shell, type the
db.<method name>
without the parenthesis (()
), as in thefollowing example which will return the implementation of the methoddb.updateUser()
:
- db.updateUser
[1] | If the deployment runs with access control, the operationreturns different values based on user privileges. SeelistDatabases Behavior for details. |
Collection Help
In the mongo
shell:
- To see the list of collections in the current database, use the
show collections
command:
- show collections
See also
- To see the help for methods available on the collection objects(e.g.
db.<collection>
), use thedb.<collection>.help()
method:
- db.collection.help()
<collection>
can be the name of a collection that exists,although you may specify a collection that doesn’t exist.
- To see the collection method implementation, type the
db.<collection>.<method>
name without the parenthesis (()
),as in the following example which will return the implementation ofthesave()
method:
- db.collection.save
Cursor Help
When you perform read operations withthe find()
method in themongo
shell, you can use various cursor methods to modifythe find()
behavior and variousJavaScript methods to handle the cursor returned from thefind()
method.
- To list the available modifier and cursor handling methods, use the
db.collection.find().help()
command:
- db.collection.find().help()
<collection>
can be the name of a collection that exists,although you may specify a collection that doesn’t exist.
- To see the implementation of the cursor method, type the
db.<collection>.find().<method>
name without the parenthesis(()
), as in the following example which will return theimplementation of thetoArray()
method:
- db.collection.find().toArray
Some useful methods for handling cursors are:
hasNext()
which checks whether thecursor has more documents to return.next()
which returns the next document andadvances the cursor position forward by one.forEach(<function>)
which iterates thewhole cursor and applies the<function>
to each document returnedby the cursor. The<function>
expects a single argument whichcorresponds to the document from each iteration.
For examples on iterating a cursor and retrieving the documents fromthe cursor, see cursor handling. Seealso Cursor for all available cursor methods.
Wrapper Object Help
To get a list of the wrapper classes available in the mongo
shell, such as BinData()
, type help misc
in themongo
shell:
- help misc
See also