Skip to content

Commit 4a53704

Browse files
committed
update code snippet include
1 parent 9fdbaa4 commit 4a53704

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

source/includes/fundamentals/code-snippets/Transaction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111

1212
public class Transaction {
1313
public static void main(String[] args) {
14-
// Connect to MongoDB
14+
// start transaction
1515
String connectionString = "<connection string>"; // Replace with your connection string
1616
try (MongoClient mongoClient = MongoClients.create(connectionString)) {
1717
MongoDatabase database = mongoClient.getDatabase("transaction_db");
1818
MongoCollection<Document> collection = database.getCollection("books");
19-
// start transaction
19+
2020
// Set transaction options
2121
TransactionOptions txnOptions = TransactionOptions.builder()
2222
.writeConcern(WriteConcern.MAJORITY)
2323
.build();
2424

2525
try (ClientSession session = mongoClient.startSession()) {
2626

27-
// Use withTransaction and lambda for transactional operations
27+
// Use withTransaction and lambda for transaction operations
2828
session.withTransaction(() -> {
2929
collection.insertMany(session, Arrays.asList(
3030
new Document("title", "The Bluest Eye").append("author", "Toni Morrison"),

0 commit comments

Comments
 (0)