Skip to content

Commit 35aa2f0

Browse files
committed
tweak explanation on two phase commits example
1 parent c7f7e48 commit 35aa2f0

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

source/tutorial/perform-two-phase-commits.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,25 @@ following:
181181
Apply Transaction to Both Accounts
182182
``````````````````````````````````
183183

184-
Continue by applying the transaction to both accounts. The
185-
:method:`~db.collection.update()` query will prevent you from
186-
applying the transaction *if* the transaction is *not* already
187-
marked as pending. Use the following :method:`~db.collection.update()`
188-
operation:
184+
Continue by applying the transaction to both accounts using the
185+
:method:`~db.collection.update()` method.
186+
187+
In the query for the :method:`~db.collection.update()`, the condition
188+
``pendingTransactions: {$ne: t._id}`` prevents the update from applying
189+
the transaction ``t`` to an account if the ``pendingTransactions``
190+
field for the account contains the ``_id`` of the transaction ``t``:
189191

190192
.. code-block:: javascript
191193

192-
db.accounts.update({name: t.source, pendingTransactions: {$ne: t._id}}, {$inc: {balance: -t.value}, $push: {pendingTransactions: t._id}})
193-
db.accounts.update({name: t.destination, pendingTransactions: {$ne: t._id}}, {$inc: {balance: t.value}, $push: {pendingTransactions: t._id}})
194+
db.accounts.update(
195+
{ name: t.source, pendingTransactions: { $ne: t._id } },
196+
{ $inc: { balance: -t.value }, $push: { pendingTransactions: t._id } }
197+
)
198+
db.accounts.update(
199+
{ name: t.destination, pendingTransactions: { $ne: t._id } },
200+
{ $inc: { balance: t.value }, $push: { pendingTransactions: t._id } }
201+
)
202+
194203
db.accounts.find()
195204

196205
The :method:`~db.collection.find()` operation will return the

0 commit comments

Comments
 (0)