@@ -18,7 +18,7 @@ Overview
18
18
In this guide, you can learn how to perform **compound operations**.
19
19
20
20
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
22
22
separately, there's a chance someone else may alter the document between
23
23
both operations. MongoDB prevents this by placing a write lock on the
24
24
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
44
44
:dedent:
45
45
:start-after: begin insertDocs
46
46
:end-before: end insertDocs
47
-
48
47
.. include:: /includes/fundamentals/tea-sample-data-ending.rst
49
48
50
49
.. _golang-find-and-delete:
@@ -58,10 +57,14 @@ the specified query filter and deletes it. The method returns a
58
57
59
58
.. note::
60
59
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.
65
68
66
69
Modify Behavior
67
70
~~~~~~~~~~~~~~~
@@ -141,11 +144,15 @@ document.
141
144
142
145
.. note::
143
146
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.
148
152
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
+
149
156
Modify Behavior
150
157
~~~~~~~~~~~~~~~
151
158
0 commit comments