Skip to content

Commit 0481b2c

Browse files
author
Sam Kleinman
committed
DOCS-484: counter edits
1 parent 4190cb6 commit 0481b2c

File tree

5 files changed

+83
-63
lines changed

5 files changed

+83
-63
lines changed

source/includes/note-ref-equality.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
.. note::
22

3-
To signify ``equal to`` (``=``), MongoDB defaults to the JSON ``{
4-
key:value }`` structure. For example, the query:
3+
To express ``equal to`` (e.g. ``=``) in the MongoDB query language,
4+
use JSON ``{ key:value }`` structure. Consider the following
5+
prototype:
56

67
.. code-block:: javascript
78
89
db.collection.find( { field: value } )
910
10-
selects all the documents where the ``field`` equals ``value``.
11+
For example:
12+
13+
.. code-block:: javascript
14+
15+
db.collection.find( { a: 42 } )
16+
17+
This query selects all the documents the where the ``a`` field
18+
holds a value of ``42``.

source/reference/operator/all.txt

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,53 @@ $all
66

77
.. operator:: $all
88

9-
*Syntax*: ``{ field: { $all: [ < value1 > , < value2 > ... ] }``
9+
*Syntax*: ``{ field: { $all: [ <value> , <value1> ... ] }``
1010

1111
:operator:`$all` selects the documents where the ``field`` is an
12-
array and contains all the ``<values>`` in the array.
12+
array and contains all items (e.g. ``<value>``, ``<value1>``, etc.)
13+
in the array.
1314

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

1617
.. code-block:: javascript
1718

18-
db.inventory.find( { tags: { $all: [ "appliances", "school" ] } } )
19+
db.inventory.find( { tags: { $all: [ "appliances", "school", "book" ] } } )
1920

20-
to select all documents in ``inventory`` where ``tags`` contains all
21-
the elements in the array ``[ "appliances", "school" ]``. So, in the case of:
21+
This query selects all documents in the ``inventory`` collection
22+
where the ``tags`` field contains an array with the elements,
23+
``appliances``, ``school``, and ``technology``.
24+
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:
2228

23-
- a document with ``tags`` equal to ``[ "school", "book", "bag",
24-
"headphone", "appliances" ]`` *and*
25-
- a document with ``tags`` equal to ``[ "appliances",
26-
"school" ]``,
27-
28-
the above query will return both documents.
29+
.. code-block:: javascript
2930

30-
Although :operator:`$all` is most meaningful when queried against an array
31-
``field``, you can use :operator:`$all` to query against a non-array ``field``.
31+
[ "school", "book", "bag", "headphone", "appliances" ]
32+
[ "appliances", "school", "book" ]
3233

33-
For example, you could query:
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:
3437

3538
.. code-block:: javascript
3639

3740
db.inventory.find( { qty: { $all: [ 50 ] } } )
3841

39-
to select all documents in ``inventory`` where the integer ``qty``
40-
equals ``50``; **however** you should, instead, use:
42+
**However**, use the following form to express the same query:
4143

4244
.. code-block:: javascript
4345

4446
db.inventory.find( { qty: 50 } )
45-
47+
48+
Both queries will select all documents in the ``inventory``
49+
collection where the value of the ``qty`` field equals ``50``.
50+
4651
.. note::
4752

4853
In most cases, MongoDB does not treat arrays as sets. This
49-
operator provides a notable exception to this general approach.
54+
operator provides a notable exception to this approach.
5055

5156
.. seealso::
5257
:method:`find() <db.collection.find()>`, :method:`update()
53-
<db.collection.update()>`, :operator:`$set`.
58+
<db.collection.update()>`, and :operator:`$set`.

source/reference/operator/and.txt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,51 @@ $and
1010

1111
*Syntax*: ``{ $and: [ { <expression1> }, { <expression2> } , ... , { <expressionN> } ] }``
1212

13-
:operator:`$and` performs a logical ``AND`` operation on an array of
14-
*two or more* ``<expressions>`` and selects the
15-
documents that satisfy *all* the ``<expressions>`` in the array.
13+
:operator:`$and` performs a logical ``AND`` operation on an array
14+
of *two or more* expressions (e.g. ``<expression1>``,
15+
``<expression2>``, etc.) and selects the documents that satisfy
16+
*all* the expressions in the array.
1617

17-
For example, you would query:
18+
Consider the following example:
1819

1920
.. code-block:: javascript
2021

2122
db.inventory.find({ $and: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } )
2223

23-
to select all documents in ``inventory`` where:
24+
This query will select all documents in the ``inventory``
25+
collection where:
2426

2527
- ``price`` equals ``1.99`` **and**
2628
- ``qty`` is less than ``20`` **and**
2729
- ``sale`` is ``true``.
2830

2931
MongoDB provides an implicit ``AND`` operation when specifying a
30-
comma separated list of expressions. For example, you can write the
32+
comma separated list of expressions. For example, you may write the
3133
above query as:
3234

3335
.. code-block:: javascript
3436

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

37-
38-
However, you need to use the :operator:`$and` operator when you need an
39-
``AND`` operation on the value of a single field.
40-
41-
For example, you would query:
42-
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:
42+
4343
.. code-block:: javascript
4444

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

47-
to update a single document in ``inventory`` where:
48-
49-
- ``price`` does not equal ``1.99`` **and**
50-
- ``price`` exists.
47+
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:
50+
51+
- does not equal ``1.99`` **and**
52+
- exists.
5153

5254
.. seealso::
5355

5456
:method:`find() <db.collection.find()>`, :method:`update()
5557
<db.collection.update()>`, :operator:`$ne`, :operator:`$exists`,
5658
:operator:`$set`.
5759

58-
60+

source/reference/operator/gte.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@ $gte
99
*Syntax*: ``{field: {$gte: value} }``
1010

1111
:operator:`$gte` selects the documents where the ``field`` is
12-
greater than or equal to (i.e. ``>=``) the specified ``value``.
13-
14-
For example, you would query:
12+
greater than or equal to (i.e. ``>=``) a specified value
13+
(e.g. ``value``.) Consider the following example:
1514

1615
.. code-block:: javascript
1716

1817
db.inventory.find( { qty: { $gte: 20 } } )
1918

20-
to select all documents in ``inventory`` where ``qty`` is greater than
21-
or equal to ``20``.
19+
This query would select all documents in ``inventory`` where
20+
``qty`` is greater than or equal to ``20``.
2221

23-
You may use the :operator:`$lt` operator to select fields from
24-
embedded documents. For example, you would query:
22+
You may use the :operator:`$gte` operator to select fields from
23+
embedded documents, as in the following example:
2524

2625
.. code-block:: javascript
2726

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

30-
to update a single document in ``inventory`` where the field ``fee``
31-
from the embedded document ``carrier`` is greater than ``2``.
29+
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``.
3232

3333
.. seealso::
3434

3535
:method:`find() <db.collection.find()>`, :method:`update()
36-
<db.collection.update()>`, :operator:`$set`.
36+
<db.collection.update()>`, :operator:`$set`.

source/reference/operator/in.txt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,37 @@ $in
99
*Syntax*: ``{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }``
1010

1111
:operator:`$in` selects the documents where the ``field`` equals any
12-
value in the specified ``array``.
13-
14-
For example, you would query:
12+
value in the specified array (e.g. ``<value1>``, <value2>``, etc.)
13+
Consider the following example:
1514

1615
.. code-block:: javascript
1716

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

20-
to select all documents in ``inventory`` where ``qty`` is either ``5`` or ``15``.
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.
2124

22-
Although you could write the above query using the :operator:`$or`
23-
operator, :operator:`$in` is preferred over :operator:`$or` when
24-
performing equality checks for the same.
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
2530

26-
If the ``field`` is an array, then ``{ field: { $in: array } }``
27-
is true *if* at least one element of the ``field`` is found in the ``array``.
31+
{ field: { $in: [ array ] } }
2832

29-
For example, the query:
33+
Consider the following example:
3034

3135
.. code-block:: javascript
3236

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

35-
will update a single document in ``inventory`` where at least one
36-
element of the ``tags`` array matches an element in ``["appliances",
37-
"school"]``.
39+
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"]``.
3843

3944
.. seealso::
4045

0 commit comments

Comments
 (0)