Skip to content

Commit a430e20

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCSP-11906 find and modify atomicity (#661) (#708)
* DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity * DOCSP-11906-find-and-modify-atomicity Co-authored-by: jason-price-mongodb <[email protected]> Co-authored-by: jason-price-mongodb <[email protected]>
1 parent df17581 commit a430e20

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

source/core/security-transport-encryption.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ For more information, see:
226226

227227
- :doc:`/tutorial/configure-x509-member-authentication`
228228

229+
.. _fips-mode:
230+
229231
FIPS Mode
230232
---------
231233

source/core/write-operations-atomicity.txt

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,44 @@ Concurrency Control
3232
Concurrency control allows multiple applications to run concurrently
3333
without causing data inconsistency or conflicts.
3434

35-
One approach is to create a :ref:`unique index <index-type-unique>` on a
36-
field that can only have unique values. This prevents insertions or
37-
updates from creating duplicate data. Create a unique index on multiple
38-
fields to force uniqueness on that combination of field values. For
39-
examples of use cases, see :ref:`update() and Unique Index
40-
<update-with-unique-indexes>` and :ref:`findAndModify() and Unique Index
41-
<upsert-and-unique-index>`.
35+
A :dbcommand:`findAndModify` operation on a document is atomic: if the
36+
find condition matches a document, the update is performed on that
37+
document. Concurrent queries and additional updates on that document are
38+
not affected until the current update is complete.
39+
40+
Consider the following example:
41+
42+
- A collection with two documents:
43+
44+
.. code-block:: javascript
45+
46+
db.myCollection.insertMany( [
47+
{ _id: 0, a: 1, b: 1 },
48+
{ _id: 1, a: 1, b: 1 }
49+
] )
50+
51+
- Two of the following :dbcommand:`findAndModify` operations run
52+
concurrently:
4253

43-
Another approach is to specify the expected current value of a field in
44-
the query predicate for the write operations.
54+
.. code-block:: javascript
55+
56+
db.myCollection.findAndModify( {
57+
query: { a: 1 },
58+
update: { $inc: { b: 1 }, $set: { a: 2 } }
59+
} )
60+
61+
After the :dbcommand:`findAndModify` operations are complete, it is
62+
guaranteed that ``a`` and ``b`` in both documents are set to ``2``.
63+
64+
.. seealso::
65+
66+
:ref:`findAndModify() Upsert Example <findAndModify-upsert-example>`
67+
68+
You can also create a :ref:`unique index <index-type-unique>` on a field
69+
so that it can only have unique values. This prevents inserts and
70+
updates from creating duplicate data. You can create a unique index
71+
on multiple fields to ensure the combination of field values is unique.
72+
For an example, see :ref:`findAndModify() Upsert with Unique Index
73+
<upsert-and-unique-index>`.
4574

4675
.. seealso:: :doc:`/core/read-isolation-consistency-recency`

source/includes/md5-and-scram-sha-1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ If you use :ref:`SCRAM-SHA-1 <authentication-scram-sha-1>`:
33
- :term:`md5` is necessary but is not used for cryptographic purposes,
44
and
55

6-
- if you use :ref:`FIPS mode <fips-overview>`, then instead of
6+
- if you use :ref:`FIPS mode <fips-mode>`, then instead of
77
:ref:`SCRAM-SHA-1 <authentication-scram-sha-1>` use:
88

99
- :ref:`SCRAM-SHA-256 <authentication-scram-sha-256>`,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ This method performs the following actions:
356356
If no document matched the ``query`` condition, the method
357357
returns ``null``.
358358

359+
.. _findAndModify-upsert-example:
360+
359361
Upsert
360362
~~~~~~
361363

0 commit comments

Comments
 (0)