Articles → MONGODB → Transaction In MongoDB
Transaction In MongoDB
Purpose
Creating A Cluster In Mongodb Atlas
Add An Admin Access User In Cluster
Connect To The Cluster
mongosh "mongodb+srv://[cluster_name].vyoy2.mongodb.net/" --apiVersion 1 --username [username]
Transaction
const session = db.getMongo().startSession();
session.startTransaction();
const db = session.getDatabase("test");
db.users.insertOne({ name: "user1" });
db.users.insertOne({ name: "user2" });
session.commitTransaction();
session.endSession();
session.abortTransaction();