Skip to content

Commit 52769b3

Browse files
committed
DOCS-484, DOCS-382, DOCS-281 Update operators ref docs and redirect compact command
1 parent 0481b2c commit 52769b3

File tree

15 files changed

+231
-188
lines changed

15 files changed

+231
-188
lines changed

source/reference/operator/all.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ $all
88

99
*Syntax*: ``{ field: { $all: [ <value> , <value1> ... ] }``
1010

11-
:operator:`$all` selects the documents where the ``field`` is an
12-
array and contains all items (e.g. ``<value>``, ``<value1>``, etc.)
11+
:operator:`$all` selects the documents where the ``field`` holds an
12+
array and contains all elements (e.g. ``<value>``, ``<value1>``, etc.)
1313
in the array.
1414

15-
For example:
15+
Consider the following example:
1616

1717
.. code-block:: javascript
1818

@@ -22,24 +22,25 @@ $all
2222
where the ``tags`` field contains an array with the elements,
2323
``appliances``, ``school``, and ``technology``.
2424

25-
Therefore, the above query will match documents in the
26-
``inventory`` collection that have a ``tags`` that hold *either* of
27-
the following arrays:
25+
Therefore, the above query will match documents in the ``inventory``
26+
collection that have a ``tags`` field that hold *either* of the
27+
following arrays:
2828

2929
.. code-block:: javascript
3030

3131
[ "school", "book", "bag", "headphone", "appliances" ]
3232
[ "appliances", "school", "book" ]
3333

34-
:operator:`$all` exists describe and specify arrays in MongoDB
35-
queries. you may use :operator:`$all` to select against a
36-
non-array ``field``, as in the following example:
34+
The :operator:`$all` operator exists to describe and specify arrays
35+
in MongoDB queries. However, you may use the :operator:`$all`
36+
operator to select against a non-array ``field``, as in the
37+
following example:
3738

3839
.. code-block:: javascript
3940

4041
db.inventory.find( { qty: { $all: [ 50 ] } } )
4142

42-
**However**, use the following form to express the same query:
43+
**However**, use the following form to express the same query:
4344

4445
.. code-block:: javascript
4546

source/reference/operator/and.txt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ $and
2424
This query will select all documents in the ``inventory``
2525
collection where:
2626

27-
- ``price`` equals ``1.99`` **and**
28-
- ``qty`` is less than ``20`` **and**
29-
- ``sale`` is ``true``.
27+
- ``price`` field value equals ``1.99`` **and**
28+
- ``qty`` field value is less than ``20`` **and**
29+
- ``sale`` field value is equal to ``true``.
3030

3131
MongoDB provides an implicit ``AND`` operation when specifying a
3232
comma separated list of expressions. For example, you may write the
@@ -36,25 +36,23 @@ $and
3636

3737
db.inventory.find( { price: 1.99, qty: { $lt: 20 } , sale: true } )
3838

39-
For queries that require an ``AND`` operation on the value of a
40-
single field, you *must* use the :operator:`$and` operator. For
41-
example:
39+
If, however, a query requires an ``AND`` operation on the same
40+
field, you *must* use the :operator:`$and` operator as in the
41+
following example:
4242

4343
.. code-block:: javascript
4444

4545
db.inventory.update( { $and: [ { price: { $ne: 1.99 } }, { price: { $exists: true } } ] }, { $set: { qty: 15 } } )
4646

4747
This :method:`update() <db.collection.update()>` operation will set
48-
the value of the ``qty`` field in documents where the value of the
49-
``price`` field:
48+
the value of the ``qty`` field in documents where:
5049

51-
- does not equal ``1.99`` **and**
52-
- exists.
50+
- the ``price`` field value does not equal ``1.99`` **and**
51+
- the ``price`` field exists.
5352

5453
.. seealso::
5554

5655
:method:`find() <db.collection.find()>`, :method:`update()
5756
<db.collection.update()>`, :operator:`$ne`, :operator:`$exists`,
5857
:operator:`$set`.
59-
60-
58+

source/reference/operator/exists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ $exists
1313
``exists``. For SQL ``exists``, refer to the :operator:`$in`
1414
operator.
1515

16-
For example, you would query:
16+
Consider the following example:
1717

1818
.. code-block:: javascript
1919

2020
db.inventory.find( { $and: [ { qty: { $exists: true } }, { qty: { $nin: [ 5, 15 ] } } ] } )
2121

22-
to select all documents in ``inventory`` where ``qty`` exists *and* does
23-
not equal either ``5`` nor ``15``.
22+
This query will select all documents in the ``inventory`` collection
23+
where the ``qty`` field exists *and* its value does not equal either
24+
``5`` nor ``15``.
2425

2526
The above query used the :operator:`$and` operator because the query
26-
performs an ``AND`` operation on the value of a single field and is
27+
performs an ``AND`` operation on the value of the same field and is
2728
not specific to the :operator:`$exists` operator.
2829

2930
.. seealso::
3031

3132
:method:`find() <db.collection.find()>`, :operator:`$and`,
32-
:operator:`$nin``, :operator:`$in``.
33+
:operator:`$nin`, :operator:`$in`.

source/reference/operator/gt.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@ $gt
88

99
*Syntax*: ``{field: {$gt: value} }``
1010

11-
:operator:`$gt` selects those documents where the ``field`` is greater
12-
than (i.e. ``>``) the specified ``value``.
11+
:operator:`$gt` selects those documents where the value of the
12+
``field`` is greater than (i.e. ``>``) the specified ``value``.
1313

14-
For example, you would query:
14+
Consider the following example:
1515

1616
.. code-block:: javascript
1717

1818
db.inventory.find( { qty: { $gt: 20 } } )
1919

20-
to select all documents in ``inventory`` where ``qty`` is greater than
21-
``20``.
20+
This query will select all documents in the ``inventory`` collection
21+
where the ``qty`` field value is greater than ``20``.
2222

23-
You may use the :operator:`$lt` operator to select fields from
24-
embedded documents. For example, you would query:
23+
Consider the following example which uses the :operator:`$gt`
24+
operator with a field from an embedded document:
2525

2626
.. code-block:: javascript
2727

2828
db.inventory.update( { "carrier.fee": { $gt: 2 } }, { $set: { price: 9.99 } } )
2929

30-
to update a single document in ``inventory`` where the field ``fee``
31-
from the embedded document ``carrier`` is greater than ``2``.
32-
30+
This :method:`update() <db.collection.update()>` operation will set
31+
the value of the ``price`` field in the documents that contain the
32+
embedded document ``carrier`` whose ``fee`` field value is
33+
greater than ``2``.
34+
3335
.. seealso::
3436

3537
:method:`find() <db.collection.find()>`, :method:`update()

source/reference/operator/gte.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,30 @@ $gte
88

99
*Syntax*: ``{field: {$gte: value} }``
1010

11-
:operator:`$gte` selects the documents where the ``field`` is
12-
greater than or equal to (i.e. ``>=``) a specified value
13-
(e.g. ``value``.) Consider the following example:
11+
:operator:`$gte` selects the documents where the value of the
12+
``field`` is greater than or equal to (i.e. ``>=``) a specified
13+
value (e.g. ``value``.)
14+
15+
Consider the following example:
1416

1517
.. code-block:: javascript
1618

1719
db.inventory.find( { qty: { $gte: 20 } } )
1820

1921
This query would select all documents in ``inventory`` where
20-
``qty`` is greater than or equal to ``20``.
22+
the ``qty`` field value is greater than or equal to ``20``.
2123

22-
You may use the :operator:`$gte` operator to select fields from
23-
embedded documents, as in the following example:
24+
Consider the following example which uses the :operator:`$gte`
25+
operator with a field from an embedded document:
2426

2527
.. code-block:: javascript
2628

2729
db.inventory.update( { "carrier.fee": { $gte: 2 } }, { $set: { price: 9.99 } } )
2830

2931
This :method:`update() <db.collection.update()>` operation will set
30-
the value of the ``price`` field where the ``fee`` field in the
31-
document embedded in the ``carrier`` field is greater than ``2``.
32+
the value of the ``price`` field that contain the embedded document
33+
``carrier`` whose``fee`` field value is greater than or equal to
34+
``2``.
3235

3336
.. seealso::
3437

source/reference/operator/in.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@ $in
88

99
*Syntax*: ``{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }``
1010

11-
:operator:`$in` selects the documents where the ``field`` equals any
12-
value in the specified array (e.g. ``<value1>``, <value2>``, etc.)
11+
:operator:`$in` selects the documents where the ``field`` value
12+
equals any value in the specified array (e.g. ``<value1>``,
13+
``<value2>``, etc.)
14+
1315
Consider the following example:
1416

1517
.. code-block:: javascript
1618

1719
db.inventory.find( { qty: { $in: [ 5, 15 ] } } )
1820

19-
This query will select to select all documents in ``inventory``
20-
where ``qty`` is either ``5`` or ``15``. Although you can express
21-
this query using the :operator:`$or` operator, prefer
22-
:operator:`$in` in favor of :operator:`$or` when performing
23-
equality checks on a single field.
21+
This query will select to select all documents in the ``inventory``
22+
collection where the ``qty`` field value is either ``5`` or
23+
``15``. Although you can express this query using the
24+
:operator:`$or` operator, choose the :operator:`$in` operator rather
25+
than the :operator:`$or` operator when performing equality checks on
26+
the same field.
2427

25-
If the field holds an array, then the following expression is true
26-
*if* any element specified with the :operator:`$in` expression is
27-
in the array.
28-
29-
.. code-block:: javascript
28+
If the ``field`` holds an array, then the :operator:`$in` operator
29+
selects the documents whose ``field`` holds an array that contains
30+
at least one element that matches a value in the specified array
31+
(e.g. ``<value1>``, ``<value2>``, etc.)
3032

31-
{ field: { $in: [ array ] } }
32-
3333
Consider the following example:
3434

3535
.. code-block:: javascript
3636

3737
db.inventory.update( { tags: { $in: ["appliances", "school"] } }, { $set: { sale:true } } )
3838

3939
This :method:`update() <db.collection.update()>` operation will set
40-
the value of ``sale`` in the ``inventory`` collection where at
41-
least one element of the ``tags`` array matches an element in the
42-
array ``["appliances", "school"]``.
40+
the ``sale`` field value in the ``inventory`` collection where the
41+
``tags`` field holds an array with at least one element matching an
42+
element in the array ``["appliances", "school"]``.
4343

4444
.. seealso::
4545

source/reference/operator/lt.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ $lt
88

99
*Syntax*: ``{field: {$lt: value} }``
1010

11-
:operator:`$lt` selects the documents where the ``field`` is less
12-
than (i.e. ``<``) the specified ``value``.
11+
:operator:`$lt` selects the documents where the value of the
12+
``field`` is less than (i.e. ``<``) the specified ``value``.
1313

14-
For example, you would query:
14+
Consider the following example:
1515

1616
.. code-block:: javascript
1717

1818
db.inventory.find( { qty: { $lt: 20 } } )
1919

20-
to select all documents in ``inventory`` where ``qty`` is less than
21-
``20``.
20+
This query will select all documents in the ``inventory`` collection
21+
where the ``qty`` field value is less than ``20``.
22+
23+
Consider the following example which uses the :operator:`$lt`
24+
operator with a field from an embedded document:
2225

23-
You may use the :operator:`$lt` operator to select fields from
24-
embedded documents. For example, you would query:
25-
2626
.. code-block:: javascript
2727

2828
db.inventory.update( { "carrier.fee": { $lt: 20 } }, { $set: { price: 9.99 } } )
29-
30-
to update a single document in ``inventory`` where the field ``fee``
31-
from the embedded document ``carrier`` is less than ``20``.
29+
30+
This :method:`update() <db.collection.update()>` operation will set
31+
the ``price`` field value in the documents that contain the
32+
embedded document ``carrier`` whose ``fee`` field value is less
33+
than ``20``.
3234

3335
.. seealso::
3436

source/reference/operator/lte.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@ $lte
88

99
*Syntax*: ``{ field: { $lte: value} }``
1010

11-
:operator:`$lte` selects the documents where the ``field`` is less
12-
than or equal to (i.e. ``<=``) the specified ``value``.
11+
:operator:`$lte` selects the documents where the value of the
12+
``field`` is less than or equal to (i.e. ``<=``) the specified
13+
``value``.
1314

14-
For example, you would query:
15+
Consider the following example:
1516

1617
.. code-block:: javascript
1718

1819
db.inventory.find( { qty: { $lte: 20 } } )
19-
20-
to select all documents in ``inventory`` where ``qty`` is less than or
21-
equal to ``20``.
2220

23-
You may use the :operator:`$lt` operator to select fields from
24-
embedded documents. For example, you would query:
21+
This query will select all documents in the ``inventory`` collection
22+
where the ``qty`` field value is less than or equal to ``20``.
23+
24+
Consider the following example which uses the :operator:`$lt`
25+
operator with a field from an embedded document:
2526

2627
.. code-block:: javascript
2728

2829
db.inventory.update( { "carrier.fee": { $lte: 5 } }, { $set: { price: 9.99 } } )
29-
30-
to update a single document in ``inventory`` where the field ``fee``
31-
from the embedded document ``carrier`` is less than or equal to
32-
``2``.
33-
30+
31+
This :method:`update() <db.collection.update()>` operation will set
32+
the ``price`` field value in the documents that contain the embedded
33+
document ``carrier`` whose ``fee`` field value is less than or equal
34+
to ``5``.
35+
3436
.. seealso::
3537

3638
method:`find() <db.collection.find()>`, :method:`update()

source/reference/operator/mod.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,35 @@ $mod
88

99
*Syntax*: ``{ field: { $mod: [ divisor, remainder ]} }``
1010

11-
:operator:`$mod` selects the documents where the ``field`` divided
11+
:operator:`$mod` selects the documents where the ``field`` value divided
1212
by the ``divisor`` has the specified ``remainder``.
1313

14-
For example, you would query:
14+
Consider the following example:
1515

1616
.. code-block:: javascript
1717

1818
db.inventory.find( { qty: { $mod: [ 4, 0 ] } } )
1919

20-
to select all documents in ``inventory`` where the ``qty`` modulo
21-
``4`` equals ``3``, such as documents with ``qty`` equal to ``0`` or
22-
``12``.
20+
This query will select all documents in the ``inventory`` collection
21+
where the ``qty`` field value modulo ``4`` equals ``3``, such as
22+
documents with ``qty`` value equal to ``0`` or ``12``.
2323

24-
In some cases, you can query using :operator:`$mod` rather than the
25-
more expensive :operator:`$where` operator. So, you can query:
24+
In some cases, you can query using the :operator:`$mod` operator
25+
rather than the more expensive :operator:`$where` operator. Consider
26+
the following example using the :operator:`$mod` operator:
2627

2728
.. code-block:: javascript
2829

2930
db.inventory.find( { qty: { $mod: [ 4, 3 ] } } )
3031

31-
rather than using the more expensive `$where`:
32+
The above query is less expensive than the following query which
33+
uses the :operator:`$where` operator:
3234

3335
.. code-block:: javascript
3436

3537
db.inventory.find( { $where: "this.qty % 4 == 3" } )
3638

3739
.. seealso::
3840

39-
method:`find() <db.collection.find()>`, :method:`update()
41+
:method:`find() <db.collection.find()>`, :method:`update()
4042
<db.collection.update()>`, :operator:`$set`.

0 commit comments

Comments
 (0)