1
1
.. _mongo:
2
2
3
+ .. meta::
4
+ :description: The mongo shell man page
5
+ :keywords: man page, mongo, javascript, shell
6
+
3
7
.. default-domain:: mongodb
4
8
5
9
================
6
- :program:` mongo`
10
+ mongo
7
11
================
8
12
9
13
Synopsis
10
14
--------
11
15
16
+ .. describe:: mongo [--shell] [--nodb] [--norc] [--quiet] [--port <port>] [--host <host>] [--eval <JavaScript>] [-u <username>] [--username <username>] [-p <password>] [--password <password>] [--help] [-h] [--version] [--verbose] [--ipv6] [database] [file.js]
17
+
18
+ Description
19
+ -----------
20
+
12
21
:program:`mongo` is an interactive JavaScript shell interface to
13
- MongoDB. :program:`mongo` provides a powerful administrative interface
14
- for systems administrators as well as an way to test queries and
22
+ MongoDB. :program:`mongo` provides a powerful interface
23
+ for systems administrators as well as a way to test queries and
15
24
operations directly with the database. To increase the flexibility of
16
25
:program:`mongo`, the shell provides a fully functional JavaScript
17
- environment. This manual page, addresses the basic invocation of the
26
+ environment. This document addresses the basic invocation of the
18
27
:program:`mongo` shell and an overview of its usage.
19
28
20
29
.. STUB -- This manual contains more extensive documentation of :program:`mongo` in the ":doc:`/mongo`" document.
@@ -26,84 +35,84 @@ Options
26
35
27
36
.. program:: mongo
28
37
29
- .. option :: --shell
38
+ .. cmdoption :: --shell
30
39
31
40
If you invoke the :program:`mongo` and specify a :term:`JavaScript`
32
41
file as an argument, or ":option:`mongo --eval`" the
33
- :option:`--shell` provides the user with a shell prompt after the
42
+ :option:`--shell` option provides the user with a shell prompt after the
34
43
file finishes executing.
35
44
36
- .. option :: --nodb
45
+ .. cmdoption :: --nodb
37
46
38
47
Use this option to prevent the shell from connecting to any
39
48
database instance.
40
49
41
- .. option :: --norc
50
+ .. cmdoption :: --norc
42
51
43
52
By default :program:`mongo` runs the ``~/.mongorc.js`` file when it
44
53
starts. Use this option to prevent the shell from sourcing this
45
54
file on start up.
46
55
47
- .. option :: --quiet
56
+ .. cmdoption :: --quiet
48
57
49
58
Silences output from the shell during the connection process.
50
59
51
- .. option :: --port <PORT>
60
+ .. cmdoption :: --port <PORT>
52
61
53
62
Specify the port where the :program:`mongod` or :program:`mongos`
54
63
instance is listening. Unless specified :program:`mongo` connects
55
64
to :program:`mongod` instances on port 27017, which is the default
56
65
:program:`mongod` port.
57
66
58
- .. option :: --host <HOSTNAME>
67
+ .. cmdoption :: --host <HOSTNAME>
59
68
60
69
Specific the host where the :program:`mongod` or :program:`mongos` is running to
61
70
connect to as ``<HOSTNAME>``. By default :program:`mongo` will attempt
62
71
to connect to MongoDB process running on the localhost.
63
72
64
- .. option :: --eval <JAVASCRIPT>
73
+ .. cmdoption :: --eval <JAVASCRIPT>
65
74
66
75
Evaluates a JavaScript specified as an argument to this
67
76
option. :program:`mongo` does not load its own environment when evaluating
68
- code: as a result many convinces of the shell environment are not
77
+ code: as a result many options of the shell environment are not
69
78
available.
70
79
71
- .. option :: --username <USERNAME>, -u <USERNAME>
80
+ .. cmdoption :: --username <USERNAME>, -u <USERNAME>
72
81
73
82
Specify a username to authenticate to the MongoDB instance, if your
74
83
database requires authentication. Use in conjunction with the
75
84
:option:`mongo --password` option to supply a password.
76
85
77
- .. option :: --password <password>, -p <password>
86
+ .. cmdoption :: --password <password>, -p <password>
78
87
79
88
Specify a password to authenticate to the MongoDB instance, if your
80
89
database requires authentication. Use in conjunction with the
81
90
:option:`mongo --username` option to supply a username. If you
82
91
specify a :option:`--username <mongo --username>` without the
83
- :option:`--password` option, :program:`mongo` will prompt for a
92
+ :option:`mongo --password` option, :program:`mongo` will prompt for a
84
93
password interactively.
85
94
86
- .. option :: --help, -h
95
+ .. cmdoption :: --help, -h
87
96
88
97
Returns a basic help and usage text.
89
98
90
- .. option :: --version
99
+ .. cmdoption :: --version
91
100
92
101
Returns the version of the shell.
93
102
94
- .. option :: --verbose
103
+ .. cmdoption :: --verbose
95
104
96
105
Increases the verbosity of the output of the shell during the
97
106
connection process.
98
107
99
- .. option :: --ipv6
108
+ .. cmdoption :: --ipv6
100
109
101
110
Enables IPv6 support that allows :program:`mongo` to connect
102
111
to the MongoDB instance using an IPv6 network. All MongoDB programs
103
112
and processes, including :program:`mongo`, disable IPv6
104
113
support by default.
105
114
106
- .. option :: <db address>
115
+ .. cmdoption :: <db address>
107
116
108
117
Specify the "database address" of the database to connect to. For
109
118
example: ::
@@ -122,15 +131,13 @@ Options
122
131
123
132
.. _mongo-shell-file:
124
133
125
- .. option :: <file.js>
134
+ .. cmdoption :: <file.js>
126
135
127
136
Optionally, specify a JavaScript file as the final argument to the
128
137
shell. The shell will run the file and then exit. Use the
129
- :option:`mongo --shell` to return to a shell after the file
138
+ :option:`mongo --shell` option to return to a shell after the file
130
139
finishes running.
131
140
132
- This should be the last address
133
-
134
141
Usage
135
142
-----
136
143
@@ -156,7 +163,7 @@ values for your situation and substitute or omit the :option:`--port`
156
163
as needed.
157
164
158
165
To execute a JavaScript file without evaluating the ``~/.mongorc.js``
159
- file before starting a sell session, use the following form:
166
+ file before starting a shell session, use the following form:
160
167
161
168
.. code-block:: sh
162
169
@@ -172,3 +179,66 @@ the :option:`--eval <mongo --eval>` option, use the following form:
172
179
Note the use of single quotes (e.g. ``'``) to enclose the JavaScript,
173
180
as well as the additional JavaScript required to generate this
174
181
output.
182
+
183
+ Files
184
+ -----
185
+
186
+ :file:`~/.dbshell`
187
+
188
+ :program:`mongo` maintains a history of commands in the `.dbshell`
189
+ file.
190
+
191
+ .. note:
192
+
193
+ Authentication commands (such as :dbcommand:`authenticate`,
194
+ :method:`db.addUser()`) will not be saved in the history file.
195
+
196
+ .. warning:
197
+
198
+ Versions of Windows :command:`mongo.exe` earlier than 2.2.0
199
+ will save the `.dbshell` file in the :command:`mongo.exe`
200
+ working directory.
201
+
202
+ :file:`~/.mongorc.js`
203
+
204
+ :program:`mongo` will read `.mongorc.js` from the home directory
205
+ of the user invoking :program:`mongo`.
206
+ Specify the :option:`mongo --norc` option to disable
207
+ reading `.mongorc.js`.
208
+
209
+ :file:`/tmp/mongo_edit{<time_t>}.js`
210
+
211
+ Created by :program:`mongo` when editing a file. If the file
212
+ exists :program:`mongo` will append an integer from 1 to 10 to
213
+ the time value to attempt to create a unique file.
214
+
215
+ :file:`%TEMP%\mongo_edit{<time_t>}.js`
216
+
217
+ Created by :command:`mongo.exe` on Windows when editing a file.
218
+ If the file
219
+ exists :program:`mongo` will append an integer from 1 to 10 to
220
+ the time value to attempt to create a unique file.
221
+
222
+ Environment
223
+ -----------
224
+
225
+ .. envvar:: EDITOR
226
+
227
+ Specify the path to an editor to use with the `edit` shell command.
228
+ A JavaScript variable `EDITOR` will override the value of
229
+ :envvar:`EDITOR`.
230
+
231
+ .. envvar:: HOME
232
+
233
+ Specify the path to the home directory where `.mongorc.js` will be
234
+ read from and `.dbshell` will be written to.
235
+
236
+ .. envvar:: HOMEDRIVE
237
+
238
+ Specify the Windows path to the home directory where `.mongorc.js` will be
239
+ read from and `.dbshell` will be written to.
240
+
241
+ .. envvar:: HOMEPATH
242
+
243
+ Specify the Windows path to the home directory where `.mongorc.js` will be
244
+ read from and `.dbshell` will be written to.
0 commit comments