|
| 1 | +.. _mongosh-help: |
| 2 | + |
| 3 | +======================= |
| 4 | +Access ``mongosh`` Help |
| 5 | +======================= |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: twocols |
| 14 | + |
| 15 | +This document provides a brief overview of the help available in |
| 16 | +:binary:`~bin.mongosh`. |
| 17 | + |
| 18 | +.. _mongosh-help-command-line: |
| 19 | + |
| 20 | +Command Line Help |
| 21 | +----------------- |
| 22 | + |
| 23 | +To see the options for running the :binary:`~bin.mongosh` executable |
| 24 | +and connecting to a deployment, use the :option:`--help <mongosh |
| 25 | +--help>` option from the command line: |
| 26 | + |
| 27 | +.. code-block:: bash |
| 28 | + |
| 29 | + mongosh --help |
| 30 | + |
| 31 | +``mongosh`` Shell Help |
| 32 | +---------------------- |
| 33 | + |
| 34 | +To see the help available in the :binary:`~bin.mongosh` console, type |
| 35 | +``help`` inside a running :binary:`~bin.mongosh` console: |
| 36 | + |
| 37 | +.. code-block:: javascript |
| 38 | + |
| 39 | + help |
| 40 | + |
| 41 | +.. _mongo-shell-help-db: |
| 42 | + |
| 43 | +Database Help |
| 44 | +------------- |
| 45 | + |
| 46 | +You can view database level information from inside the |
| 47 | +:binary:`~bin.mongosh` console: |
| 48 | + |
| 49 | +- By default :binary:`~bin.mongosh` shows the current database in the |
| 50 | + prompt. You can also see the current database by running the ``db`` |
| 51 | + command: |
| 52 | + |
| 53 | + .. code-block:: javascript |
| 54 | + |
| 55 | + db |
| 56 | + |
| 57 | +- To see the list of databases available to you on the server, use the |
| 58 | + ``show dbs`` command: |
| 59 | + |
| 60 | + .. code-block:: javascript |
| 61 | + |
| 62 | + show dbs |
| 63 | + |
| 64 | + ``show databases`` is an alias for ``show dbs``. |
| 65 | + |
| 66 | + .. tip:: |
| 67 | + |
| 68 | + The list of databases will change depending on your access |
| 69 | + authorizations. For more information on access restrictions for |
| 70 | + viewing databases, see :dbcommand:`listDatabases`. |
| 71 | + |
| 72 | +- To see help for the available :manual:`database methods |
| 73 | + </reference/method/js-database/>` you can use with the ``db`` object, |
| 74 | + run :method:`db.help()`: |
| 75 | + |
| 76 | + .. code-block:: javascript |
| 77 | + |
| 78 | + db.help() |
| 79 | + |
| 80 | +.. _mongosh-help-collection: |
| 81 | + |
| 82 | +Collection Help |
| 83 | +--------------- |
| 84 | + |
| 85 | +You can view collection level information from inside the |
| 86 | +:binary:`~bin.mongosh` console. |
| 87 | + |
| 88 | +These help methods accept a collection name, ``<collection>``, but you |
| 89 | +can also use the generic term, "collection", or even a collection that |
| 90 | +does not exist. |
| 91 | + |
| 92 | +- By default :binary:`~bin.mongosh` shows the current database in the |
| 93 | + prompt. To see the list of collections in the current database, use |
| 94 | + the ``show collections`` command: |
| 95 | + |
| 96 | + .. code-block:: javascript |
| 97 | + |
| 98 | + show collections |
| 99 | + |
| 100 | +- To see the help for methods available on collection objects |
| 101 | + use ``db.<collection>.help()`` method: |
| 102 | + |
| 103 | + .. code-block:: javascript |
| 104 | + |
| 105 | + db.collection.help() |
| 106 | + |
| 107 | +- To see the help for a particular method, use |
| 108 | + ``db.<collection>.<method>.help()``: |
| 109 | + |
| 110 | + .. code-block:: javascript |
| 111 | + |
| 112 | + db.collection.getIndexes.help() |
| 113 | + |
| 114 | + |
| 115 | +.. _mongosh-help-cursor: |
| 116 | + |
| 117 | +Cursor Help |
| 118 | +----------- |
| 119 | + |
| 120 | +Use :ref:`cursor methods <mongosh-cursor-methods>` to modify |
| 121 | +:ref:`read operations <read-operations-queries>` that use |
| 122 | +:method:`~db.collection.find()`. |
| 123 | + |
| 124 | +- To list the available modifier and cursor handling methods, use the |
| 125 | + ``db.collection.find().help()`` command: |
| 126 | + |
| 127 | + .. code-block:: javascript |
| 128 | + |
| 129 | + db.collection.find().help() |
| 130 | + |
| 131 | +This help call accepts a collection name, ``<collection>``, but you |
| 132 | +can also use the generic term, "collection", or even a collection which |
| 133 | +does not exist. |
| 134 | + |
| 135 | +Some useful methods for handling cursors are: |
| 136 | + |
| 137 | +- :method:`~cursor.hasNext()` checks if the cursor has more documents. |
| 138 | + |
| 139 | +- :method:`~cursor.next()` returns the next document and moves the |
| 140 | + cursor position forward by one. |
| 141 | + |
| 142 | +- :method:`forEach(\<function\>) <cursor.forEach()>` applies the |
| 143 | + ``<function>`` to each document returned by the cursor. |
| 144 | + |
| 145 | +For a list of available cursor methods, see :ref:`js-query-cursor-methods`. |
| 146 | + |
| 147 | +.. seealso:: |
| 148 | + |
| 149 | + - :ref:`run-commands` provides guidance on how to use |
| 150 | + :binary:`~bin.mongosh`. |
| 151 | + - :ref:`mdb-shell-methods` lists available methods. |
| 152 | + |
0 commit comments