Skip to content

Commit 4397a2a

Browse files
committed
DOCS-799 incorporate scotts comments
1 parent c5bc889 commit 4397a2a

File tree

11 files changed

+197
-107
lines changed

11 files changed

+197
-107
lines changed

source/reference/meta-query-operators.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@ Introduction
1111

1212
In addition to the :doc:`MongoDB Query Operators
1313
</reference/operators>`, there are a number of "meta" operators that
14-
you may use to modify the output or behavior of a
15-
query. Specify these modifiers to a :method:`db.collection.find()` query, in the
16-
following forms (for the :program:`mongo` shell):
14+
you may use to modify the output or behavior of a query. On the server,
15+
MongoDB treats the query and the options as a single object. The
16+
:program:`mongo` shell may provide :ref:`cursor methods
17+
<js-query-cursor-methods>` for these options. When possible, use these
18+
methods; otherwise, you can add these options using either of the
19+
following syntax:
1720

1821
.. code-block:: javascript
1922

20-
db.collection.find( { <QUERY> } )._addSpecial( <MODIFIER> )
21-
db.collection.find( { $query: { <QUERY> }, <MODIFIER> } )
22-
23-
Here, the query specified by ``<QUERY>`` runs on the collection named
24-
``collection`` with the operation specified by the ``<MODIFIER>``. The
25-
results are then processed by a modifier expression selected from the
26-
following list. MongoDB treats the query and the
27-
modifiers as a single object, with the :operator:`$query` and the meta
28-
operators included in a single document.
23+
db.collection.find( { <query> } )._addSpecial( <option> )
24+
db.collection.find( { $query: { <query> }, <option> } )
2925

3026
Modifiers
3127
---------
3228

33-
Many of the operators have corresponding :doc:`methods
34-
in the shell </reference/javascript>`.
29+
Many of these operators have corresponding :ref:`methods in the shell
30+
<js-query-cursor-methods>`. These methods provide a straightforward and
31+
user-friendly interface and are the preferred way to add these options.
3532

3633
.. include:: operator/returnKey.txt
3734
:start-after: mongodb

source/reference/operator/comment.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ $comment
1414

1515
.. code-block:: javascript
1616

17-
db.collection.find( { <QUERY> } )._addSpecial( "$comment", <comment to add> )
18-
db.collection.find( { $query: { <QUERY> }, $comment: <comment to add> } )
17+
db.collection.find( { <query> } )._addSpecial( "$comment", <comment to add> )
18+
db.collection.find( { $query: { <query> }, $comment: <comment to add> } )

source/reference/operator/explain.txt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ $explain
1111
the process and indexes used to return the query. This may provide
1212
useful insight when attempting to optimize a query.
1313

14-
Retrieve the query plan by adding the :operator:`$explain` operator
15-
to a :method:`find() <db.collection.find()>` query, as in the
16-
following examples:
14+
The :program:`mongo` shell provides the :method:`cursor.explain()`
15+
method:
1716

1817
.. code-block:: javascript
1918

20-
db.collection.find()._addSpecial( "$explain", 1 )
21-
db.collection.find( { $query: {}, $explain: 1 } )
19+
db.collection.find().explain()
2220

23-
The JavaScript function :method:`cursor.explain()` provides equivalent
24-
functionality in the :program:`mongo` shell. See the following
25-
example, which is equivalent to the above:
21+
You can also specify the option in either of the following forms:
2622

2723
.. code-block:: javascript
2824

29-
db.collection.find().explain()
25+
db.collection.find()._addSpecial( "$explain", 1 )
26+
db.collection.find( { $query: {}, $explain: 1 } )

source/reference/operator/hint.txt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ $hint
66

77
.. operator:: $hint
88

9-
Use the :operator:`$hint` operator to force the query optimizer to
10-
use a specific index to fulfill the query. Use :operator:`$hint`
11-
for testing query performance and indexing strategies. Consider
12-
the following operations:
9+
The :operator:`$hint` operator forces the query optimizer to use a
10+
specific index to fulfill the query. You can use :operator:`$hint`
11+
for testing query performance and indexing strategies. The
12+
:program:`mongo` shell provides the :method:`cursor.hint()` method:
1313

1414
.. code-block:: javascript
1515

16-
db.collection.find()._addSpecial( "$hint", { _id : 1 } )
17-
db.collection.find( { $query: {}, $hint: { _id : 1 } } )
16+
db.collection.find().hint( { age: 1 } )
1817

19-
These are equivalent to the following :method:`cursor.hint()` method that
20-
may be more familiar to you:
18+
This operation returns all documents in the collection named
19+
``collection`` using the index on the ``age`` field. Use this
20+
operator to override MongoDB's default index selection process and
21+
pick indexes manually.
2122

22-
.. code-block:: javascript
23+
You can also specify the option in either of the following forms:
2324

24-
db.collection.find().hint( { _id: 1 } )
25+
.. code-block:: javascript
2526

26-
These operations return all documents in the collection named
27-
``collection`` using the index on the ``_id`` field. Use this
28-
operator to override MongoDB's default index selection process and
29-
pick indexes manually.
27+
db.collection.find()._addSpecial( "$hint", { age : 1 } )
28+
db.collection.find( { $query: {}, $hint: { age : 1 } } )

source/reference/operator/max.txt

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,72 @@ $max
88

99
Specify a :operator:`$max` value to specify the *exclusive* upper
1010
bound for a specific index in order to constrain the results of
11-
:method:`find() <db.collection.find()>`. Consider the following
12-
operations on a collection named ``collection`` that has an index
13-
``{ age: 1 }``:
11+
:method:`find() <db.collection.find()>`. The :program:`mongo` shell
12+
provides the :method:`cursor.max()` wrapper method:
1413

1514
.. code-block:: javascript
1615

17-
db.collection.find()._addSpecial( "$max", { age : 100 } )
18-
db.collection.find( { $query: {}, $max: { age: 100 } } )
16+
db.collection.find( { <query> } ).max( { field1: <max value>, ... fieldN: <max valueN> } )
1917

20-
These are equivalent to the following :method:`cursor.max()` method that
21-
may be more familiar to you:
18+
You can also specify the option with either of the two forms:
2219

2320
.. code-block:: javascript
2421

25-
db.collection.find().max( { age: 100 } )
26-
22+
db.collection.find( { <query> } )._addSpecial( "$max", { field1: <max value1>, ... fieldN: <max valueN> } )
23+
db.collection.find( { $query: { <query> }, $max: { field1: <max value1>, ... fieldN: <max valueN> } } )
24+
25+
The :operator:`$max` specifies the upper bound for *all* keys of a
26+
specific index *in order*.
27+
28+
Consider the following operations on a collection named
29+
``collection`` that has an index ``{ age: 1 }``:
30+
31+
.. code-block:: javascript
32+
33+
db.collection.find( { <query> } ).max( { age: 100 } )
34+
2735
This operation above limits the query to those documents where the
2836
field ``age`` is less than ``100`` using the index ``{ age: 1 }``.
29-
You can explicitly specify the particular index with the
30-
:operator:`$hint`. Otherwise, MongoDB selects the index using the
31-
fields in the ``indexbounds``; however, if multiple indexes exist on
32-
same fields with different sort orders, the selection of the index
33-
may be ambiguous.
37+
38+
You can explicitly specify the corresponding index with
39+
:method:`cursor.hint()`. Otherwise, MongoDB selects the index using
40+
the fields in the ``indexbounds``; however, if multiple indexes
41+
exist on same fields with different sort orders, the selection of
42+
the index may be ambiguous.
43+
44+
Consider a collection named ``collection`` that has the following
45+
two indexes:
46+
47+
.. code-block:: javascript
48+
49+
{ age: 1, type: -1 }
50+
{ age: 1, type: 1 }
3451

35-
Use operation alone or in conjunction with :operator:`$min`
36-
to limit results to a specific range for the same index.
52+
Without explicitly using :method:`cursor.hint()`, it is unclear
53+
which index the following operation will select:
54+
55+
.. code-block:: javascript
56+
57+
db.collection.find().max( { age: 50, type: 'B' } )
58+
59+
Use operation alone or in conjunction with :operator:`$min` to limit
60+
results to a specific range for the *same* index, as in the
61+
following example:
62+
63+
.. code-block:: javascript
64+
65+
db.collection.find().min( { age: 20 } ).max( { age: 25 } )
3766

3867
.. note::
3968

40-
In most cases, you should avoid this operator in favor of
41-
:operator:`$lt`.
69+
Because :method:`cursor.max()` requires an index on a field, and
70+
forces the query to use this index, you may prefer the
71+
:operator:`$lt` operator for the query if possible. Consider the
72+
following example:
73+
74+
.. code-block:: javascript
75+
76+
db.collection.find( { _id: 7 } ).max( { age: 25 } )
77+
78+
The query will use the index on the ``age`` field, even if the
79+
index on ``_id`` may be better.

source/reference/operator/maxScan.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ $maxScan
1111

1212
.. code-block:: javascript
1313

14-
db.collection.find( { <QUERY> } )._addSpecial( "$maxScan" , <number> )
15-
db.collection.find( { $query: { <QUERY> }, $maxScan: <number> } )
14+
db.collection.find( { <query> } )._addSpecial( "$maxScan" , <number> )
15+
db.collection.find( { $query: { <query> }, $maxScan: <number> } )
1616

1717
Use this modifier to prevent potentially long running queries from
1818
disrupting performance by scanning through too much data.

source/reference/operator/min.txt

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,72 @@ $min
88

99
Specify a :operator:`$min` value to specify the *inclusive* lower
1010
bound for a specific index in order to constrain the results of
11-
:method:`find() <db.collection.find()>`. Consider the following
12-
operations on a collection named ``collection`` that has an index
13-
``{ age: 1 }``:
11+
:method:`find() <db.collection.find()>`. The :program:`mongo` shell
12+
provides the :method:`cursor.min()` wrapper method:
1413

1514
.. code-block:: javascript
1615

17-
db.collection.find()._addSpecial("$min" , { age : 20 } )
18-
db.collection.find( { $query: {}, $min: { age: 20 } } )
16+
db.collection.find( { <query> } ).min( { field1: <min value>, ... fieldN: <min valueN>} )
1917

20-
These are equivalent to the following :method:`cursor.min()` method that
21-
may be more familiar to you:
18+
You can also specify the option with either of the two forms:
19+
20+
.. code-block:: javascript
21+
22+
db.collection.find( { <query> } )._addSpecial( "$min", { field1: <min value1>, ... fieldN: <min valueN> } )
23+
db.collection.find( { $query: { <query> }, $min: { field1: <min value1>, ... fieldN: <min valueN> } } )
24+
25+
The :operator:`$min` specifies the lower bound for *all* keys of a
26+
specific index *in order*.
27+
28+
Consider the following operations on a collection named
29+
``collection`` that has an index ``{ age: 1 }``:
2230

2331
.. code-block:: javascript
2432

2533
db.collection.find().min( { age: 20 } )
26-
27-
These operations limits the query to those documents where the field
28-
``age`` is at least ``20`` using the index ``{ age: 1 }``. You can
29-
explicitly specify the particular index with :operator:`$hint`.
30-
Otherwise, MongoDB selects the index using the fields in the
31-
``indexbounds``; however, if multiple indexes exist on same fields
32-
with different sort orders, the selection of the index may be
33-
ambiguous.
34-
35-
Use operation alone or in conjunction with :operator:`$max` to limit
36-
results to a specific range for the same index.
34+
35+
These operations limit the query to those documents where the field
36+
``age`` is at least ``20`` using the index ``{ age: 1 }``.
37+
38+
You can explicitly specify the corresponding index with
39+
:method:`cursor.hint()`. Otherwise, MongoDB selects the index using
40+
the fields in the ``indexbounds``; however, if multiple indexes
41+
exist on same fields with different sort orders, the selection of
42+
the index may be ambiguous.
43+
44+
Consider a collection named ``collection`` that has the following
45+
two indexes:
46+
47+
.. code-block:: javascript
48+
49+
{ age: 1, type: -1 }
50+
{ age: 1, type: 1 }
51+
52+
Without explicitly using :method:`cursor.hint()`, it is unclear
53+
which index the following operation will select:
54+
55+
.. code-block:: javascript
56+
57+
db.collection.find().min( { age: 20, type: 'C' } )
58+
59+
You can use :operator:`$min` in conjunction with :operator:`$max` to
60+
limit results to a specific range for the *same* index, as in the
61+
following example:
62+
63+
.. code-block:: javascript
64+
65+
db.collection.find().min( { age: 20 } ).max( { age: 25 } )
3766

3867
.. note::
3968

40-
In most cases, you should avoid this operator in favor of
41-
:operator:`$gte`.
69+
Because :method:`cursor.min()` requires an index on a field, and
70+
forces the query to use this index, you may prefer the
71+
:operator:`$gte` operator for the query if possible. Consider the
72+
following example:
73+
74+
.. code-block:: javascript
75+
76+
db.collection.find( { _id: 7 } ).min( { age: 25 } )
77+
78+
The query will use the index on the ``age`` field, even if the
79+
index on ``_id`` may be better.

source/reference/operator/orderby.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ $orderby
77
.. operator:: $orderby
88

99
The :operator:`$orderby` operator sorts the results of a query in
10-
ascending or descending order. Consider the following operations:
10+
ascending or descending order.
11+
12+
The :program:`mongo` shell provides the :method:`cursor.sort()`
13+
method:
1114

1215
.. code-block:: javascript
1316

14-
db.collection.find()._addSpecial( "$orderby", { age : -1 } )
15-
db.collection.find( { $query: {}, $orderby: { age : -1 } } )
17+
db.collection.find().sort( { age: -1 } )
1618

17-
These are equivalent to the following :method:`cursor.sort()` method that
18-
may be more familiar to you:
19+
You can also specify the option in either of the following forms:
1920

2021
.. code-block:: javascript
2122

22-
db.collection.find().sort( { age: -1 } )
23+
db.collection.find()._addSpecial( "$orderby", { age : -1 } )
24+
db.collection.find( { $query: {}, $orderby: { age : -1 } } )
2325

2426
These examples return all documents in the collection named
2527
``collection`` sorted by the ``age`` field in descending order.
@@ -29,9 +31,7 @@ $orderby
2931

3032
Unless you have a index for the specified key pattern, use
3133
:operator:`$orderby` in conjunction with :operator:`$maxScan` and/or
32-
:method:`cursor.limit()` to avoid requiring MongoDB to perform a large
33-
in-memory sort. :method:`cursor.limit()` increases the speed and reduce
34-
the amount of memory required to return this query by way of an
35-
optimized algorithm.
36-
37-
.. seealso:: :operator:`$query` operator
34+
:method:`cursor.limit()` to avoid requiring MongoDB to perform a
35+
large in-memory sort. The :method:`cursor.limit()` increases the
36+
speed and reduces the amount of memory required to return this query
37+
by way of an optimized algorithm.

source/reference/operator/returnKey.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ $returnKey
1313

1414
.. code-block:: javascript
1515

16-
db.collection.find( { <QUERY> } )._addSpecial( "$returnKey", true )
17-
db.collection.find( { $query: { <QUERY> }, $returnKey: true } )
16+
db.collection.find( { <query> } )._addSpecial( "$returnKey", true )
17+
db.collection.find( { $query: { <query> }, $returnKey: true } )

source/reference/operator/showDiskLoc.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ $showDiskLoc
66

77
.. operator:: $showDiskLoc
88

9-
Use the following modifier to display the disk location information
10-
as an additional field ``$diskLoc`` in the returned documents. Use
11-
one of the following forms:
9+
:operator:`$showDiskLoc` option adds a field ``$diskLoc`` to the returned
10+
documents. The ``$diskLoc`` field contains the disk location
11+
information.
12+
13+
The :program:`mongo` shell provides the :method:`cursor.showDiskLoc()`
14+
method:
15+
16+
.. code-block:: javascript
17+
18+
db.collection.find().showDiskLoc()
19+
20+
You can also specify the option in either of the following forms:
1221

1322
.. code-block:: javascript
1423

15-
db.collection.find( { <QUERY> } )._addSpecial("$showDiskLoc" , true)
16-
db.collection.find( { $query: { <QUERY> }, $showDiskLoc: true } )
24+
db.collection.find( { <query> } )._addSpecial("$showDiskLoc" , true)
25+
db.collection.find( { $query: { <query> }, $showDiskLoc: true } )

0 commit comments

Comments
 (0)