Docs Menu

Access mongosh Help

On this page

  • Command Line Help
  • mongosh Shell Help
  • Database Help
  • Collection Help
  • Cursor Help

This document provides a brief overview of the help available in mongosh.

To see the options for running the mongosh executable and connecting to a deployment, use the --help option from the command line:

mongosh --help

To see the help available in the mongosh console, type help inside a running mongosh console:

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 the db 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 for show dbs.

    Tip

    The 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, run db.help():

    db.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 the show 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()

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.

Tip
See also:
Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.