@@ -181,16 +181,25 @@ following:
181
181
Apply Transaction to Both Accounts
182
182
``````````````````````````````````
183
183
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``:
189
191
190
192
.. code-block:: javascript
191
193
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
+
194
203
db.accounts.find()
195
204
196
205
The :method:`~db.collection.find()` operation will return the
0 commit comments