Skip to content

Commit e0c451b

Browse files
(DOCSP-42573) Update transactions in Functions info about read/write settings (#860)
Removing any mentions + code of creating a configuration object that sets user's preferred read/write settings and passing it to the session method. These settings are not configured in this context and not respected. ## Pull Request Info Jira ticket: https://jira.mongodb.org/browse/DOCSP-42573 ### Staging Links <!-- start insert-links --> </li><li><a href=https://deploy-preview-860--app-services.netlify.app/functions/mongodb/write>functions/mongodb/write</a></li> <!-- end insert-links --> ### Reminder Checklist Before merging your PR, make sure to check a few things. - [ ] Did you tag pages appropriately? - genre - programming_language - meta.keywords - meta.description - [ ] Describe your PR's changes in the Release Notes section - [ ] Create a Jira ticket for related docs-realm work, if any ### Release Notes <!-- - **Define Data Access Permissions** - Data Access Role Examples: Update CRUD Permissions example screenshots and copyable JSON --> ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-app-services/blob/master/REVIEWING.md)
2 parents ea26db9 + ac5f355 commit e0c451b

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

source/functions/mongodb/api/snippets/transactions.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
exports = function () {
22
const client = context.services.get("mongodb-atlas");
33

4-
db = client.db("exampleDatabase");
4+
const db = client.db("exampleDatabase");
55

6-
accounts = db.collection("accounts");
7-
browniePointsTrades = db.collection("browniePointsTrades");
6+
const accounts = db.collection("accounts");
7+
const browniePointsTrades = db.collection("browniePointsTrades");
88

99
// create user accounts with initial balances
1010
accounts.insertOne({ name: "henry", browniePoints: 42 });
@@ -34,18 +34,11 @@ async function tradeBrowniePoints(
3434
// Step 1: Start a Client Session
3535
const session = client.startSession();
3636

37-
// Step 2: Optional. Define options to use for the transaction
38-
const transactionOptions = {
39-
readPreference: "primary",
40-
readConcern: { level: "local" },
41-
writeConcern: { w: "majority" },
42-
};
43-
44-
// Step 3: Use withTransaction to start a transaction, execute the callback, and commit (or abort on error)
37+
// Step 2: Use withTransaction to start a transaction, execute the callback, and commit (or abort on error)
4538
// Note: The callback for withTransaction MUST be async and/or return a Promise.
4639
try {
4740
await session.withTransaction(async () => {
48-
// Step 4: Execute the queries you would like to include in one atomic transaction
41+
// Step 3: Execute the queries you would like to include in one atomic transaction
4942
// Important:: You must pass the session to the operations
5043
await accounts.updateOne(
5144
{ name: userSubtractPoints },
@@ -65,12 +58,12 @@ async function tradeBrowniePoints(
6558
},
6659
{ session }
6760
);
68-
}, transactionOptions);
61+
});
6962
} catch (err) {
70-
// Step 5: Handle errors with a transaction abort
63+
// Step 4: Handle errors with a transaction abort
7164
await session.abortTransaction();
7265
} finally {
73-
// Step 6: End the session when you complete the transaction
66+
// Step 5: End the session when you complete the transaction
7467
await session.endSession();
7568
}
7669
}

source/functions/mongodb/write.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,12 @@ To perform a transaction:
383383
1. Obtain and start a client session with ``client.startSession()``.
384384

385385
#. Call ``session.withTransaction()`` to define the transaction. The
386-
method takes an async callback function and, optionally, a
387-
configuration object that defines custom :manual:`read and write
388-
settings
389-
</core/transactions/#read-concern-write-concern-read-preference>` for
390-
the transaction.
386+
method takes an async callback function.
391387

392388
.. code-block:: javascript
393389

394390
session.withTransaction(async () => {
395391
// ... Run MongoDB operations in this callback
396-
}, {
397-
readPreference: "primary",
398-
readConcern: { level: "local" },
399-
writeConcern: { w: "majority" },
400392
})
401393

402394
#. In the transaction callback function, run the MongoDB queries that
@@ -439,7 +431,7 @@ To perform a transaction:
439431
}
440432

441433
The following example creates two users, "henry" and "michelle", and
442-
a uses a transaction to move "browniePoints" between those users
434+
uses a transaction to move "browniePoints" between those users
443435
atomically:
444436

445437
.. literalinclude:: /functions/mongodb/api/snippets/transactions.js

0 commit comments

Comments
 (0)