Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a transaction in MongoDB.
MongoDB
const session = client.startSession();
session.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commitTransaction instead of startTransaction.
Calling endSession before starting a transaction.
✗ Incorrect
To begin a transaction, you must call startTransaction() on the session.
2fill in blank
mediumComplete the code to commit a transaction in MongoDB.
MongoDB
await session.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using abortTransaction instead of commitTransaction.
Calling startTransaction again instead of committing.
✗ Incorrect
To save all changes made in a transaction, use commitTransaction().
3fill in blank
hardFix the error in aborting a transaction in MongoDB.
MongoDB
await session.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commitTransaction instead of abortTransaction.
Calling endSession instead of aborting.
✗ Incorrect
To cancel all changes in a transaction, use abortTransaction().
4fill in blank
hardFill both blanks to correctly use a transaction with commit and session end.
MongoDB
try { await session.[1](); // perform operations await session.[2](); } finally { await session.endSession(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Committing before starting the transaction.
Using abortTransaction instead of commitTransaction.
✗ Incorrect
Start the transaction with startTransaction() and commit it with commitTransaction().
5fill in blank
hardFill all three blanks to abort a transaction and end the session properly.
MongoDB
try { await session.[1](); // perform operations if (error) { await session.[2](); } else { await session.commitTransaction(); } } finally { await session.[3](); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not ending the session after aborting.
Using commitTransaction instead of abortTransaction on error.
✗ Incorrect
Start the transaction, abort if error, and always end the session.