Skip to content

Commit 4473399

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCSP-47758-history-command (#396)
* DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command * DOCSP-47758-history-command --------- Co-authored-by: jason-price-mongodb <[email protected]>
1 parent 22f3b7f commit 4473399

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

source/logs/command-history.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,40 @@ text editor:
3232

3333
* - Windows
3434
- ``%UserProfile%/.mongodb/mongosh/mongosh_repl_history``
35+
36+
Starting in |mdb-shell| 2.4.0, you can use the ``history()`` command to
37+
view a list of previously executed commands. For example:
38+
39+
.. code-block:: javascript
40+
41+
history()
42+
43+
The following example output shows a list of commands in an array of
44+
strings:
45+
46+
.. code-block:: javascript
47+
:copyable: false
48+
49+
[
50+
'db.pizzaOrders.explain()',
51+
'db.pizzaOrders.find()',
52+
'db.pizzaOrders.explain.find()',
53+
'db.pizzaOrders.explain.find( {} )',
54+
'db.pizzaOrders.explain().find( {} )',
55+
'db.pizzaOrders.explain().find( orderDate, totalNumber )',
56+
'db.pizzaOrders.explain().find( orderDate: Date( "2024-03-20T10:01:12Z" ), totalNumber: 20 )',
57+
'db.pizzaOrders.explain().find( totalNumber: 20 )',
58+
'db.pizzaOrders.explain().find( { orderDate: Date( "2024-03-20T10:01:12Z" ) }, { totalNumber: 20 } )',
59+
'db.pizzaOrders.find( { orderDate: Date( "2024-03-20T10:01:12Z" ) }, { totalNumber: 20 } )',
60+
...
61+
]
62+
63+
The history is returned in chronological order.
64+
65+
``history()`` supports JavaScript array methods. You can use ``slice()``
66+
to return a section of an array. For example, to view the last 10
67+
commands, run:
68+
69+
.. code-block:: javascript
70+
71+
history().slice(-10)

source/reference/access-mdb-shell-help.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ certain database commands and obtain information on your deployment:
407407
* - ``help``
408408
- Display help.
409409

410+
* - ``history()``
411+
- Display a list of previously executed commands. Available
412+
starting in |mdb-shell| 2.4.0.
413+
410414
* - ``show collections``
411415
- Display a list of all collections for current database.
412416

0 commit comments

Comments
 (0)