@@ -6,25 +6,34 @@ Command Reference
6
6
.. highlight :: javascript
7
7
8
8
This document contains a reference to all :term: `database commands
9
- <database command> `. All commands are constructed using :term: `BSON `
10
- documents issued as queries against a special MongoDB
11
- collection named :term: `$cmd `. The JavaScript shell
12
- (i.e. :option: `mongo `,) provides the following syntax to facilitate
13
- running commands: ::
9
+ <database command> `. MongoDB constructs commands using :term: `BSON `
10
+ documents issued as queries against a special MongoDB collection named
11
+ :term: `$cmd `. The JavaScript shell (i.e. :option: `mongo `,) provides
12
+ the following syntax to facilitate running commands:
13
+
14
+ .. code-block :: javascript
14
15
15
16
db .runCommand ( { < commandname> : < value> [, options] } );
16
17
17
18
Similarly, you can run administrative commands using the following
18
- syntax: ::
19
+ syntax:
20
+
21
+ .. code-block :: javascript
22
+
23
+ db ._adminCommand ( { < commandname> : < value> [, options] } )
19
24
20
- db._adminCommand( { <commandname>: <value> [, options] } );
25
+ The ``_adminCommand `` helper is shorthand for the following JavaScript
26
+ operation:
21
27
22
- The ``_adminCommand `` helper is shorthand for "``db.getSisterDB("admin").runCommand(); ``".
28
+ .. code-block :: javascript
29
+
30
+ db .getSisterDB (" admin" ).runCommand ()
23
31
24
32
MongoDB :term: `drivers <driver> `, and the :option: `mongo ` shell may
25
33
provide helper interfaces for issuing database commands.
26
34
27
- All examples in this reference are provided as documents.
35
+ This document primarily provides examples as "prototype" documents,
36
+ with references to available shell helpers when possible.
28
37
29
38
User Commands
30
39
-------------
@@ -37,25 +46,27 @@ Sharding
37
46
38
47
.. dbcommand :: addShard
39
48
40
- The ``addShard `` command registers a new with a sharded cluster.
41
- You must run this command against a :option: `mongos ` instance. The command
42
- takes the following form: ::
49
+ The ``addShard `` command registers a new with a sharded
50
+ cluster. You must run this command against a :option: `mongos `
51
+ instance. The command takes the following form: ::
43
52
44
53
{ addshard: "<hostname>:<port>" }
45
54
46
55
Replace "``<hostname>:<port> ``" with the hostname and port of the
47
56
database instance you want to add as a shard. Because the
48
57
:option: `mongos ` instances do not have state and distribute
49
- configuration in the :term: `configdb`s , you send this
58
+ configuration in the :term: `configdbs < configdb> ` , you send this
50
59
command to only one :option: `mongos ` instance.
51
60
52
61
There are two optional parameters:
53
62
54
- - **name **. If no name is specified, a name will be automatically
55
- provided to uniquely identify the shard.
56
- - **maxSize ** Unless specified, shards will consume the total amount
57
- of available space on their machines if necessary. Use the ``maxSize `` value to
58
- limit the amount of space the database can use.
63
+ - **name **. Unless specified, a name will be automatically provided
64
+ to uniquely identify the shard.
65
+
66
+ - **maxSize ** Unless specified, shards will consume the total
67
+ amount of available space on their machines if necessary. Use the
68
+ ``maxSize `` value to limit the amount of space the database can
69
+ use.
59
70
60
71
.. note ::
61
72
@@ -144,7 +155,7 @@ Sharding
144
155
145
156
Each database in a sharded cluster is assigned a primary shard. If the shard you want to remove
146
157
is also the primary of one the cluster's databases, then you must manually move the database to
147
- a new shard. This can be only after the shard has been drained. See the :mongodb:command : `moveprimary ` command
158
+ a new shard. This can be only after the shard has been drained. See the :dbcommand : `moveprimary ` command
148
159
for details.
149
160
150
161
Once all chunks and databases have been removed from the shard, you
@@ -161,9 +172,9 @@ Sharding
161
172
162
173
When the command returns, the database's primary location will have been
163
174
shifted to the designated :term: `shard `. To fully decomission a
164
- shard, use the :mongodb: dbcommand: `removeshard ` command.
175
+ shard, use the :dbcommand: `removeshard ` command.
165
176
166
- .. warning :: Do not use :mongodb: dbcommand:`moveprimary` if you have
177
+ .. warning :: Do not use :dbcommand:`moveprimary` if you have
167
178
sharded collections and the :term: `draining ` process has not
168
179
completed.
169
180
@@ -260,8 +271,9 @@ Aggregation
260
271
261
272
Only the ``map `` and ``reduce `` options are required, all other
262
273
fields are optional. The ``map `` and ``reduce `` functions are
263
- written in JavaScript. See :doc: `/core/map-reduce ` for more information
264
- on using the ``mapReduce `` command.
274
+ written in JavaScript.
275
+
276
+ .. seealso :: ":js:func:`mapReduce()`" and ":doc:`/core/map-reduce`"
265
277
266
278
.. slave-ok
267
279
@@ -281,8 +293,8 @@ TODO lacking a lot of documentation. Can you describe each option in the way you
281
293
282
294
{ findAndModify: collection, <options> }
283
295
284
- The shell and many :term: `drivers <driver> ` also provide a
285
- `` db. findAndModify(); `` method.
296
+ The shell and many :term: `drivers <driver> ` provide a
297
+ :js:func: ` findAndModify() ` helper method.
286
298
287
299
The following options are available:
288
300
@@ -320,7 +332,11 @@ TODO: link to more complete documentation with common examples.
320
332
321
333
Here, all distinct values of the field (or "``key ``") ``age `` are
322
334
returned in documents that match the query "``{ field: { $exists:
323
- true } ``". **Note that the query is optional **.
335
+ true } ``".
336
+
337
+ .. note ::
338
+
339
+ The query portion of the :dbcommand: `distinct ` is optional.
324
340
325
341
The shell and many :term: `drivers <driver> ` provide a helper method that provides
326
342
this functionality. You may prefer the following equivalent syntax: ::
@@ -340,23 +356,24 @@ are required and which are options? For instance, required options could be in b
340
356
341
357
{ eval: function() { return 3+3 } }
342
358
343
- The shell also provides a helper method, so you can express the above
344
- the above like so: ::
359
+ The shell also provides a helper method, so you can express the
360
+ above like so: ::
345
361
346
362
db.eval( function { return 3+3 } } );
347
363
348
- Note that functions entered directly into the shell will be evaluated
349
- by the shell's JavaScript interpreter . If you want to use the server's
364
+ Note the shell's Java Script interpreter evaluates functions
365
+ entered directly into the shell . If you want to use the server's
350
366
interpreter, you must run ``eval ``.
351
367
352
368
Note the following behaviors and limitations:
353
369
354
370
- ``eval `` does not work in :term: `sharded <sharding> `
355
371
environments.
356
372
357
- - The ``eval `` operation take a write lock by default. This means that writes to
358
- database aren't permitted while it's running. You can, however, disable the lock
359
- by setting the ``nolock `` flag to ``true ``. For example: ::
373
+ - The ``eval `` operation take a write lock by default. This means
374
+ that writes to database aren't permitted while it's running. You
375
+ can, however, disable the lock by setting the ``nolock `` flag to
376
+ ``true ``. For example: ::
360
377
361
378
{ eval: function() { return 3+3 }, nolock: true }
362
379
@@ -529,12 +546,12 @@ TODO: see also -- replica set config options.
529
546
.. slave-ok, admin-only
530
547
531
548
Geospatial Commands
532
- ~~~~~~~~~~~
549
+ ~~~~~~~~~~~~~~~~~~~
533
550
534
551
.. dbcommand :: geoNear
535
552
536
553
The ``geoNear `` command provides an alternative to the
537
- :mongodb: dbcommand: `$near ` operator. In addition to the
554
+ :dbcommand: `$near ` operator. In addition to the
538
555
functionality of ``$near ``, ``geoNear `` returns the distance of
539
556
each item from the specified point along with additional diagnostic
540
557
information. For example: ::
@@ -1136,9 +1153,11 @@ Diagnostics
1136
1153
.. dbcommand :: validate
1137
1154
1138
1155
The ``validate `` command checks the contents of a namespace by
1139
- scanning data structures, and indexes for correctness. The command
1156
+ scanning data structures, and indexes for correctness. The command
1140
1157
can be slow to run particularly on larger data sets. Consider the
1141
- following syntax: ::
1158
+ following syntax:
1159
+
1160
+ .. code-block :: javascript
1142
1161
1143
1162
{ validate: " collection" }
1144
1163
@@ -1151,12 +1170,25 @@ Diagnostics
1151
1170
- "``scandata: false ``" skips the scan of the base collection
1152
1171
without skipping the scan of the index.
1153
1172
1154
- The ``mongo `` shell also provides a shell wrapper which is
1155
- equivalent to the first example above: ::
1173
+ The :option: `mongo ` shell provides the :js:func: `validate() ` method
1174
+ around the :dbcommand: `validate ` command for easy use. The
1175
+ following command at the :option: `mongo ` shell is equivalent to the
1176
+ example above:
1177
+
1178
+ .. code-block :: javascript
1156
1179
1157
1180
db .collection .validate ();
1158
1181
1159
- TODO factcheck; the options on the REST interface and wiki differ
1182
+ Use one of the following forms to perform the full collection
1183
+ validation:
1184
+
1185
+ .. code-block :: javascript
1186
+
1187
+ db .collection .validate (true )
1188
+ db .runCommand ( { validate: " collection" , full: true } )
1189
+
1190
+ .. warning :: This command is resource intensive and may have an
1191
+ impact on the performance of your MongoDB instance.
1160
1192
1161
1193
.. dbcommand :: top
1162
1194
@@ -1172,7 +1204,7 @@ TODO factcheck; the options on the REST interface and wiki differ
1172
1204
- insert
1173
1205
- update
1174
1206
- remove
1175
- - commands.
1207
+ - commands
1176
1208
1177
1209
The command takes the following form: ::
1178
1210
@@ -1454,6 +1486,11 @@ Other Commands
1454
1486
1455
1487
TODO find md5 "root" argument, and other functionality.
1456
1488
1489
+ :option: `mongos ` commands
1490
+ -------------------------
1491
+
1492
+ TODO document mongos commands DOCS-112
1493
+
1457
1494
Internal Use
1458
1495
------------
1459
1496
0 commit comments