Articles → MONGODB → Transaction In MongoDB

Transaction In MongoDB






Purpose





Creating A Cluster In Mongodb Atlas




Picture showing +Create button for creating a new cluster




Picture showing a popup window will appear to specify the cloud configuration




Picture showing the screen to deploy the cluster





Add An Admin Access User In Cluster




Picture showing Add New Database user for adding the admin access to the user




Picture showing adding the admin access to the user





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();



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, August 29, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250