Access mongosh
Help
This document provides a brief overview of the help available in
mongosh
.
Command Line Help
To see the options for running the mongosh
executable
and connecting to a deployment, use the --help
option from the command line:
mongosh --help
mongosh
Shell Help
To see the help available in the mongosh
console, type
help
inside a running mongosh
console:
help
Database Help
You can view database level information from inside the
mongosh
console:
By default
mongosh
shows the current database in the prompt. You can also see the current database by running thedb
command:db To see the list of databases available to you on the server, use the
show dbs
command:show dbs show databases
is an alias forshow dbs
.TipThe list of databases will change depending on your access authorizations. For more information on access restrictions for viewing databases, see
listDatabases
.To see help for the available database methods you can use with the
db
object, rundb.help()
:db.help()
Collection Help
You can view collection level information from inside the
mongosh
console.
These help methods accept a collection name, <collection>
, but you
can also use the generic term, "collection", or even a collection that
does not exist.
By default
mongosh
shows the current database in the prompt. To see the list of collections in the current database, use theshow collections
command:show collections To see the help for methods available on collection objects use
db.<collection>.help()
method:db.collection.help() To see the help for a particular method, use
db.<collection>.<method>.help()
:db.collection.getIndexes.help()
Cursor Help
Use cursor methods to modify
read operations that use
find()
.
To list the available modifier and cursor handling methods, use the
db.collection.find().help()
command:db.collection.find().help()
This help call accepts a collection name, <collection>
, but you
can also use the generic term, "collection", or even a collection which
does not exist.
Some useful methods for handling cursors are:
hasNext()
checks if the cursor has more documents.next()
returns the next document and moves the cursor position forward by one.forEach(<function>)
applies the<function>
to each document returned by the cursor.
For a list of available cursor methods, see Cursor.
mongosh
Usage provides guidance on how to usemongosh
.mongosh
Methods lists available methods.