Complete the code to start a transaction in MongoDB.
const session = client.startSession();
session.[1]();To begin a transaction in MongoDB, you use startTransaction() on the session.
Complete the code to commit a transaction after operations.
await session.[1]();After completing operations in a transaction, you commit it with commitTransaction().
Fix the error in the code to abort a transaction properly.
try { await session.commitTransaction(); } catch (error) { await session.[1](); }
If committing a transaction fails, you should abort it using abortTransaction() to undo changes.
Fill both blanks to create a transaction that updates two collections atomically.
const session = client.startSession(); try { session.[1](); await collection1.updateOne(filter1, update1, { session }); await collection2.updateOne(filter2, update2, { session }); await session.[2](); } finally { await session.endSession(); }
Start the transaction with startTransaction() and commit it with commitTransaction() after updates.
Fill all three blanks to handle a transaction with error rollback and session cleanup.
const session = client.startSession(); try { session.[1](); await collection.updateOne(filter, update, { session }); await session.[2](); } catch (error) { await session.[3](); } finally { await session.endSession(); }
Start the transaction, commit if successful, and abort if there is an error.