Skip to content

Commit 95ed6fc

Browse files
authored
DOCSP-26830 - Clarify compound operations (#206)
* initial commit * fixes * cc feedback * fixes * cc feedback * cc feedback * cc feedback * fix * fix
1 parent 285d228 commit 95ed6fc

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

source/fundamentals/crud/compound-operations.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Overview
1818
In this guide, you can learn how to perform **compound operations**.
1919

2020
Compound operations combine a read and write operation into
21-
a single operation. If you perform a read and write operation
21+
a single operation. If you perform a read and write operation
2222
separately, there's a chance someone else may alter the document between
2323
both operations. MongoDB prevents this by placing a write lock on the
2424
document you are modifying for the duration of your compound operation.
@@ -44,7 +44,6 @@ Run the following snippet to load the documents into the ``tea.ratings`` collect
4444
:dedent:
4545
:start-after: begin insertDocs
4646
:end-before: end insertDocs
47-
4847
.. include:: /includes/fundamentals/tea-sample-data-ending.rst
4948

5049
.. _golang-find-and-delete:
@@ -58,10 +57,14 @@ the specified query filter and deletes it. The method returns a
5857

5958
.. note::
6059

61-
This method differs from the ``DeleteOne()`` method.
62-
``FindOneAndDelete()`` performs a find and delete as a single
63-
operation, and eliminates the possibility of someone altering a
64-
document between both operations.
60+
The ``FindOneAndDelete()`` method is an atomic operation, which means it prevents
61+
any other write operations from changing the matching document until it
62+
completes. The ``deleteOne()`` method is also an atomic operation, but differs from
63+
``FindOneAndDelete()`` in that you cannot specify a sort order for the
64+
matched documents.
65+
66+
If you don't need to find and delete a document in a single transaction, you can call
67+
the ``findOne()`` method followed by the ``deleteOne()`` method.
6568

6669
Modify Behavior
6770
~~~~~~~~~~~~~~~
@@ -141,11 +144,15 @@ document.
141144

142145
.. note::
143146

144-
This method differs from the ``UpdateOne()`` method.
145-
``FindOneAndUpdate()`` performs a find and update as a single
146-
operation, and eliminates the possibility of someone altering a
147-
document between both operations.
147+
The ``FindOneAndUpdate()`` method is an atomic operation, which means it prevents
148+
any other write operations from changing the matching document until it
149+
completes. The ``updateOne()`` method is also an atomic operation, but differs from
150+
``FindOneAndUpdate()`` in that you cannot specify a sort order for the
151+
matched documents.
148152

153+
If you don't need to find and update a document in a single transaction, you can call
154+
the ``findOne()`` method followed by the ``updateOne()`` method.
155+
149156
Modify Behavior
150157
~~~~~~~~~~~~~~~
151158

0 commit comments

Comments
 (0)