Skip to content

Commit 76abb1b

Browse files
(DOCSP-10995): Allow both .help and .help() in shell (#19)
* (DOCS-10995): checkpoint * (DOCS-10995): first draft * (DOCS-10995): copy review feedback * (DOCS-10995): copy review pt 2
1 parent a5703bc commit 76abb1b

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

source/reference.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Reference
1111

1212
/reference/options
1313
/reference/methods
14+
/reference/access-mdb-shell-help
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
.. _mdb-shell-help:
2+
3+
===========================
4+
Access the |mdb-shell| Help
5+
===========================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
``mongosh`` provides additional help information in its help system.
16+
This document provides an overview of accessing this help
17+
information.
18+
19+
.. tip::
20+
21+
When accessing :ref:`database <mdb-shell-help-db>` and
22+
:ref:`collection <mdb-shell-help-collection>` help in ``mongosh``,
23+
you can use the ``.help()`` and ``.help`` syntaxes interchangeably.
24+
25+
.. _mdb-shell-help-command-line:
26+
27+
Command Line Help
28+
-----------------
29+
30+
To see the list of options and help for starting ``mongosh``, use the
31+
``--help`` option from the command line:
32+
33+
.. code-block:: sh
34+
35+
mongosh --help
36+
37+
Shell Help
38+
----------
39+
40+
To see a basic list of commands you can run, in ``mongosh``, type
41+
``help``:
42+
43+
.. code-block:: javascript
44+
45+
help
46+
47+
.. _mdb-shell-help-db:
48+
49+
Database Help
50+
-------------
51+
52+
Show List of Databases
53+
To see the list of databases on the server, use the ``show dbs``
54+
command:
55+
56+
.. code-block:: javascript
57+
58+
show dbs
59+
60+
``show databases`` is an alias for ``show dbs``.
61+
62+
Show List of Database Methods
63+
To see the list of methods you can use on the ``db``
64+
object, call the ``db.help()`` method or run the ``db.help`` command:
65+
66+
.. code-block:: javascript
67+
68+
db.help()
69+
70+
The output resembles the following:
71+
72+
.. code-block:: none
73+
:copyable: false
74+
75+
Database Class:
76+
77+
getMongo Returns the current database connection
78+
getCollectionNames Returns an array containing the names of
79+
all collections in the current database.
80+
getCollectionInfos Returns an array of documents with
81+
collection information, i.e. collection
82+
name and options, for the current
83+
database.
84+
runCommand Runs an arbitrary command on the
85+
database.
86+
adminCommand Runs an arbitrary command against the
87+
admin database.
88+
aggregate Runs a specified admin/diagnostic
89+
pipeline which does not require an
90+
underlying collection.
91+
getSiblingDB Returns another database without
92+
modifying the db variable in the shell
93+
environment.
94+
getCollection Removes the current database, deleting
95+
the associated data files.
96+
dropDatabase Removes the current database, deleting
97+
the associated data files.
98+
99+
Show Help for Specific Database Method
100+
To see help for a specific database method in ``mongosh``, type the
101+
``db.<method name>``, followed by ``.help`` or ``.help()``. The
102+
following example returns help for the :method:`db.adminCommand()`
103+
method:
104+
105+
.. code-block:: javascript
106+
107+
db.adminCommand.help()
108+
109+
The output resembles the following:
110+
111+
.. code-block:: none
112+
113+
db.adminCommand({ serverStatus: 1 }):
114+
115+
Runs an arbitrary command against the admin database.
116+
117+
For more information on usage: https://docs.mongodb.com/manual/reference/method/db.adminCommand
118+
119+
Show Additional Usage Details for a Database Method
120+
To see additional usage details for a database method in ``mongosh``,
121+
type the ``db.<method name>`` without the parenthesis (``()``). The
122+
following example returns details about the
123+
:method:`db.adminCommand()` method:
124+
125+
.. code-block:: javascript
126+
127+
db.adminCommand
128+
129+
The output resembles the following:
130+
131+
.. code-block:: javascript
132+
:copyable: false
133+
134+
[Function] {
135+
serverVersions: [ '3.4.0', '4.4.0' ],
136+
returnsPromise: true,
137+
topologies: [ 0, 2, 1 ],
138+
returnType: { type: 'unknown', attributes: {} },
139+
platforms: [ 0, 1, 2 ],
140+
help: [Function] Help
141+
}
142+
143+
144+
.. _mdb-shell-help-collection:
145+
146+
Collection Help
147+
---------------
148+
149+
Show List of Collections
150+
To see the list of collections in the current database, use the
151+
``show collections`` command:
152+
153+
.. code-block:: javascript
154+
155+
show collections
156+
157+
Show List of Collection Methods
158+
To see the list of methods available on the collection objects
159+
(e.g. ``db.<collection>``), use the ``db.<collection>.help()``
160+
method:
161+
162+
.. code-block:: javascript
163+
164+
db.collection.help()
165+
166+
``<collection>`` can be the name of an existing or nonexistent
167+
collection.
168+
169+
The output resembles the following:
170+
171+
.. code-block:: none
172+
:copyable: false
173+
174+
Collection Class:
175+
176+
aggregate Calculates aggregate values for the
177+
data in a collection or a view.
178+
bulkWrite Performs multiple write operations
179+
with controls for order of execution.
180+
count Returns the count of documents that
181+
would match a find() query for the
182+
collection or view.
183+
countDocuments Returns the count of documents that
184+
match the query for a collection or view.
185+
deleteMany Removes all documents that match the
186+
filter from a collection.
187+
deleteOne Removes a single document from a
188+
collection.
189+
distinct Finds the distinct values for a specified
190+
field across a single collection or view
191+
and returns the results in an array.
192+
estimatedDocumentCount Returns the count of all documents in a
193+
collection or view.
194+
find Selects documents in a collection or view.
195+
196+
...
197+
198+
Show Help for Specific Collection Method
199+
To see help for a specific collection method in ``mongosh``, type the
200+
``db.<collection>.<method name>``, followed by ``.help`` or
201+
``.help()``. The following example returns help for the
202+
:method:`db.collection.insertOne()` method:
203+
204+
.. code-block:: javascript
205+
206+
db.collection.insertOne.help()
207+
208+
The output resembles the following:
209+
210+
.. code-block:: none
211+
:copyable: false
212+
213+
db.collection.insertOne(document, options):
214+
215+
Inserts a document into a collection.
216+
217+
For more information on usage: https://docs.mongodb.com/manual/reference/method/db.collection.insertOne
218+
219+
Show Additional Usage Details for a Collection Method
220+
To see additional usage details for a collection method in
221+
``mongosh``, type the ``db.<collection>.<method>`` name without the
222+
parenthesis (``()``) The following example returns
223+
details about the :method:`~db.collection.insertOne()` method:
224+
225+
.. code-block:: javascript
226+
227+
db.collection.insertOne
228+
229+
The output resembles the following:
230+
231+
.. code-block:: javascript
232+
:copyable: false
233+
234+
[Function] {
235+
serverVersions: [ '3.2.0', '4.4.0' ],
236+
returnsPromise: true,
237+
topologies: [ 0, 2, 1 ],
238+
returnType: { type: 'unknown', attributes: {} },
239+
platforms: [ 0, 1, 2 ],
240+
help: [Function] Help
241+
}
242+
243+
.. didn't include the cursor details from the manual help page as
244+
it seems as if most of it doesn't apply for ``mongosh``

0 commit comments

Comments
 (0)