Skip to content

Commit f2acbfa

Browse files
author
Dave
authored
DOCSP-20086 updates for update pt7 v5.2 (#160) (#187)
* DOCSP-20086 updates for update() pt7 * Add explain, gt * DOCSP-20086 gt lte lt create-inventory * gt lt ne nor not * gte * Staging fixes * Review feedback
1 parent 72166cf commit f2acbfa

File tree

11 files changed

+425
-118
lines changed

11 files changed

+425
-118
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. code-block:: javascript
2+
3+
db.inventory.insertMany( [
4+
{
5+
"item": "nuts", "quantity": 30,
6+
"carrier": { "name": "Shipit", "fee": 3 }
7+
},
8+
{
9+
"item": "bolts", "quantity": 50,
10+
"carrier": { "name": "Shipit", "fee": 4 }
11+
},
12+
{
13+
"item": "washers", "quantity": 10,
14+
"carrier": { "name": "Shipit", "fee": 1 }
15+
}
16+
] )
17+

source/includes/steps-schedule-balancer-window.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ level: 3
4141
title: "Modify the balancer's window."
4242
action:
4343
- pre: |
44-
Set the ``activeWindow`` using :method:`~db.collection.update()`,
44+
Set the ``activeWindow`` using :method:`~db.collection.updateOne()`,
4545
as in the following:
4646
language: sh
4747
code: |
48-
db.settings.update(
48+
db.settings.updateOne(
4949
{ _id: "balancer" },
5050
{ $set: { activeWindow : { start : "<start-time>", stop : "<stop-time>" } } },
5151
{ upsert: true }

source/reference/method/db.collection.explain.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ Description
3232
- :method:`~db.collection.count()`
3333
- :method:`~db.collection.find()`
3434
- :method:`~db.collection.remove()`
35-
- :method:`~db.collection.update()`
36-
3735
- - :method:`~db.collection.distinct()`
3836
- :method:`~db.collection.findAndModify()`
39-
4037
- - :method:`~db.collection.mapReduce()`
4138

4239
To use :method:`db.collection.explain()`, append one of the

source/reference/operator/query/comment.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Behavior
3131

3232
You can use the :query:`$comment` with any expression taking a query
3333
predicate, such as the query predicate in
34-
:method:`db.collection.update()` or in the :pipeline:`$match` stage of
35-
the :doc:`aggregation pipeline </meta/aggregation-quick-reference>`.
34+
:method:`db.collection.updateOne()` or in the :pipeline:`$match` stage
35+
of the :doc:`aggregation pipeline </meta/aggregation-quick-reference>`.
3636
For an example, see :ref:`ex-comment-agg-expression`.
3737

3838
Examples

source/reference/operator/query/gt.txt

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,100 @@ $gt
1010
:depth: 1
1111
:class: singlecol
1212

13+
Definition
14+
----------
15+
1316
.. query:: $gt
1417

15-
*Syntax*: ``{field: {$gt: value} }``
18+
*Syntax*: ``{ field: { $gt: value } }``
1619

1720
:query:`$gt` selects those documents where the value of the
1821
``field`` is greater than (i.e. ``>``) the specified ``value``.
1922

2023
.. include:: /includes/fact-type-bracketing.rst
2124

22-
Consider the following example:
25+
Examples
26+
--------
27+
28+
The following examples use the ``inventory`` collection. Create the
29+
collection:
30+
31+
.. include:: /includes/examples-create-inventory.rst
32+
33+
Match Document Fields
34+
~~~~~~~~~~~~~~~~~~~~~
35+
36+
Select all documents in the ``inventory`` collection where ``quantity``
37+
is greater than ``20``:
38+
39+
.. code-block:: javascript
40+
41+
db.inventory.find( { quantity: { $gt: 20 } } )
42+
43+
Example output:
44+
45+
.. code-block:: javascript
46+
47+
{
48+
_id: ObjectId("61ba25cbfe687fce2f042414"),
49+
item: 'nuts',
50+
quantity: 30,
51+
carrier: { name: 'Shipit', fee: 3 }
52+
},
53+
{
54+
_id: ObjectId("61ba25cbfe687fce2f042415"),
55+
item: 'bolts',
56+
quantity: 50,
57+
carrier: { name: 'Shipit', fee: 4 }
58+
}
2359

24-
.. code-block:: javascript
60+
Perform an Update Based on Embedded Document Fields
61+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2562

26-
db.inventory.find( { qty: { $gt: 20 } } )
63+
The following example sets the ``price`` field based on a :query:`$gt`
64+
comparison against a field in an embedded document.
2765

28-
This query will select all documents in the ``inventory`` collection
29-
where the ``qty`` field value is greater than ``20``.
66+
.. code-block:: javascript
3067

31-
Consider the following example that uses the :query:`$gt`
32-
operator with a field from an embedded document:
68+
db.inventory.updateOne(
69+
{ "carrier.fee": { $gt: 2 } }, { $set: { "price": 9.99 } }
70+
)
3371

34-
.. code-block:: javascript
72+
Example output:
3573

36-
db.inventory.update( { "carrier.fee": { $gt: 2 } }, { $set: { price: 9.99 } } )
74+
.. code-block:: javascript
3775

38-
This :method:`~db.collection.update()` operation will set
39-
the value of the ``price`` field in the first document found containing the
40-
embedded document ``carrier`` whose ``fee`` field value is
41-
greater than ``2``.
76+
{
77+
_id: ObjectId("61ba3ec9fe687fce2f042417"),
78+
item: 'nuts',
79+
quantity: 30,
80+
carrier: { name: 'Shipit', fee: 3 },
81+
price: 9.99
82+
},
83+
{
84+
_id: ObjectId("61ba3ec9fe687fce2f042418"),
85+
item: 'bolts',
86+
quantity: 50,
87+
carrier: { name: 'Shipit', fee: 4 }
88+
},
89+
{
90+
_id: ObjectId("61ba3ec9fe687fce2f042419"),
91+
item: 'washers',
92+
quantity: 10,
93+
carrier: { name: 'Shipit', fee: 1 }
94+
}
4295

43-
To set the value of the ``price`` field in *all* documents containing the
44-
embedded document ``carrier`` whose ``fee`` field value is greater than ``2``,
45-
specify the ``multi:true`` option in the :method:`~db.collection.update()` method:
96+
This :method:`~db.collection.updateOne()` operation searches for an
97+
embedded document, ``carrier``, with a subfield named ``fee``. It sets
98+
``{ price: 9.99 }`` in the first document it finds where ``fee`` has a
99+
value greater than 2.
46100

47-
.. code-block:: javascript
101+
To set the value of the ``price`` field in *all* documents where
102+
``carrier.fee`` is greater than 2, use
103+
:method:`~db.collection.updateMany()`.
48104

49-
db.inventory.update(
50-
{ "carrier.fee": { $gt: 2 } },
51-
{ $set: { price: 9.99 } },
52-
{ multi: true }
53-
)
105+
.. seealso::
54106

55-
.. seealso::
107+
- :method:`~db.collection.find()`
108+
- :update:`$set`
56109

57-
- :method:`~db.collection.find()`
58-
- :method:`~db.collection.update()`
59-
- :update:`$set`

source/reference/operator/query/gte.txt

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,96 @@ $gte
1010
:depth: 1
1111
:class: singlecol
1212

13+
Definition
14+
----------
15+
1316
.. query:: $gte
1417

15-
*Syntax*: ``{field: {$gte: value} }``
18+
*Syntax*: ``{ field: { $gte: value } }``
1619

1720
:query:`$gte` selects the documents where the value of the
1821
``field`` is greater than or equal to (i.e. ``>=``) a specified
1922
value (e.g. ``value``.)
2023

2124
.. include:: /includes/fact-type-bracketing.rst
2225

23-
Consider the following example:
26+
Examples
27+
--------
28+
29+
The following examples use the ``inventory`` collection. Create the
30+
collection:
31+
32+
.. include:: /includes/examples-create-inventory.rst
33+
34+
Match Document Fields
35+
~~~~~~~~~~~~~~~~~~~~~
36+
37+
Select all documents in the ``inventory`` collection where ``quantity``
38+
is greater than or equal to ``20``:
39+
40+
.. code-block:: javascript
41+
42+
db.inventory.find( { quantity: { $gte: 20 } } )
43+
44+
Example output:
45+
46+
.. code-block:: javascript
47+
48+
{
49+
_id: ObjectId("61bb51211b83c864e3bbe037"),
50+
item: 'nuts',
51+
quantity: 30,
52+
carrier: { name: 'Shipit', fee: 3 }
53+
},
54+
{
55+
_id: ObjectId("61bb51211b83c864e3bbe038"),
56+
item: 'bolts',
57+
quantity: 50,
58+
carrier: { name: 'Shipit', fee: 4 }
59+
}
60+
61+
Perform an Update Based on Embedded Document Fields
62+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63+
64+
The following example sets the ``price`` field based on a :query:`$gte`
65+
comparison against a field in an embedded document.
66+
67+
.. code-block:: javascript
2468

25-
.. code-block:: javascript
69+
db.inventory.updateMany(
70+
{ "carrier.fee": { $gte: 2 } }, { $set: { "price": 9.99 } }
71+
)
2672

27-
db.inventory.find( { qty: { $gte: 20 } } )
73+
Example output:
2874

29-
This query would select all documents in ``inventory`` where
30-
the ``qty`` field value is greater than or equal to ``20``.
75+
.. code-block:: javascript
3176

32-
Consider the following example which uses the :query:`$gte`
33-
operator with a field from an embedded document:
77+
{
78+
_id: ObjectId("61bb51211b83c864e3bbe037"),
79+
item: 'nuts',
80+
quantity: 30,
81+
carrier: { name: 'Shipit', fee: 3 },
82+
price: 9.99
83+
},
84+
{
85+
_id: ObjectId("61bb51211b83c864e3bbe038"),
86+
item: 'bolts',
87+
quantity: 50,
88+
carrier: { name: 'Shipit', fee: 4 },
89+
price: 9.99
90+
}
3491

35-
.. code-block:: javascript
92+
This :method:`~db.collection.updateOne()` operation searches for an
93+
embedded document, ``carrier``, with a subfield named ``fee``. It sets
94+
``{ price: 9.99 }`` in each document where ``fee`` has a value greater
95+
than or equal to 2.
3696

37-
db.inventory.update( { "carrier.fee": { $gte: 2 } }, { $set: { price: 9.99 } } )
97+
To set the value of the ``price`` field in only the first document
98+
where ``carrier.fee`` is greater than 2, use
99+
:method:`~db.collection.updateOne()`.
38100

39-
This :method:`~db.collection.update()` operation will set
40-
the value of the ``price`` field that contain the embedded document
41-
``carrier`` whose ``fee`` field value is greater than or equal to
42-
``2``.
101+
.. seealso::
43102

44-
.. seealso::
103+
- :method:`~db.collection.find()`
104+
- :update:`$set`
45105

46-
- :method:`~db.collection.find()`
47-
- :method:`~db.collection.update()`
48-
- :update:`$set`

0 commit comments

Comments
 (0)