Skip to content

Commit 11a889b

Browse files
author
Sam Kleinman
committed
DOCS-683 edits
1 parent 89fb36a commit 11a889b

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ db.collection.update()
109109
.. note::
110110

111111
The ``multi`` update operation may interleave with other
112-
write operations to that collection. For an unsharded
113-
collection, you have the option to override this behavior
114-
with the :operator:`$atomic` isolation operator,
115-
effectively isolating the update operation and blocking
112+
write operations. For unsharded
113+
collections, you can override this behavior
114+
with the :operator:`$atomic` isolation operator, which
115+
isolates the update operation and blocks
116116
other write operations during the update. See the
117117
:doc:`isolation operator </reference/operator/atomic>`.
118118

source/reference/operator/atomic.txt

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

1212
.. note::
1313

14-
The :operator:`$atomic` isolation operator does **not** mean
15-
"all-or-nothing" atomicity to the write operation.
14+
The :operator:`$atomic` isolation operator does **not** provide
15+
"all-or-nothing" atomicity for write operations.
1616

1717
Consider the following example:
1818

source/tutorial/isolate-sequence-of-operations.txt

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Isolate Sequence of Operations
44

55
.. default-domain:: mongodb
66

7-
Background
8-
----------
7+
Overview
8+
--------
99

1010
Write operations are atomic on the level of a single document: no
1111
single write operation can atomically affect more than one document or
@@ -21,32 +21,38 @@ No other operations are atomic; however, you can *isolate* a
2121
single write operation that affects multiple documents using the
2222
:doc:`isolation operator </reference/operator/atomic>`.
2323

24-
Additionally, the following patterns can manage a sequence of
25-
operations:
24+
This document describes one method of updating documents *only* if the
25+
local copy of the document reflects the current state of the document
26+
in the database. In addition the following methods provide a way to
27+
manage isolated sequences of operations:
2628

27-
- :method:`findAndModify() <db.collection.findAndModify()>`
28-
29-
- :ref:`tutorial-atomic-update-if-current`
29+
- the :method:`findAndModify() <db.collection.findAndModify()>`
30+
provides an isolated query and modify operation.
3031

3132
- :doc:`/tutorial/perform-two-phase-commits`
3233

33-
- :method:`ensureIndex() <db.collection.ensureIndex()>` to create a
34-
``unique`` index on a field
34+
- Create a :ref:`unique index <index-type-unique>`, to ensure that a
35+
key doesn't exist when you insert it.
3536

3637
.. _tutorial-atomic-update-if-current:
3738

3839
Update if Current
3940
-----------------
4041

41-
The "Update if Current" pattern queries a document, locally modifies
42-
various fields of the document, and tries to update the fields of a
43-
document *if* the fields have not changed in the collection since the
44-
query.
42+
In this patter, you will:
43+
44+
- queries for a document,
45+
46+
- modifies the fields in that document
47+
48+
- and updates the fields of a document *only if* the fields have not
49+
changed in the collection since the query.
4550

46-
Consider the following example which attempts to update the ``qty``
47-
field of a document in the ``products`` collection:
51+
Consider the following example in JavaScript which attempts to update
52+
the ``qty`` field of a document in the ``products`` collection:
4853

4954
.. code-block:: javascript
55+
:linenos:
5056

5157
var myCollection = db.products;
5258
var myDocument = myCollection.findOne( { sku: 'abc123' } );
@@ -83,19 +89,23 @@ field of a document in the ``products`` collection:
8389

8490
}
8591

86-
Consider the following modifications to the "Update if Current" strategy:
92+
Your application may require some modifications of this pattern, such
93+
as:
8794

88-
- To generalize the strategy to guarantee that the whole document has
89-
not changed rather than just certain fields, use the entire document in
90-
the query expression.
95+
- Use the entire document as the query in lines 18 and 19, to
96+
generalize the operation and guarantee that the original document
97+
was not modified, rather than ensuring that as single field was not
98+
changed.
9199

92-
- Add a version variable that is incremented upon each update operation
93-
to the documents. Use this version variable in the query expression.
100+
- Add a version variable to the document that applications increment
101+
upon each update operation to the documents. Use this version
102+
variable in the query expression. You must be able to ensure that
103+
*all* clients that connect to your database obey this constraint.
94104

95105
- Use :operator:`$set` in the update expression to modify only your
96106
fields and prevent overriding other fields.
97107

98-
.. Add link to :doc:`/tutorial/create-an-auto-increment-field` once that branch is merged since it's a special case
108+
.. Add link to :doc:`/tutorial/create-an-auto-increment-field` once that branch is merged since it's a special case
99109

100110
.. Maybe incorporate the blurb: "MongoDB does not
101111
support traditional locking and complex transactions for a number of

0 commit comments

Comments
 (0)