@@ -32,3 +32,40 @@ text editor:
32
32
33
33
* - Windows
34
34
- ``%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)
0 commit comments