0
0
MongoDBquery~10 mins

Transaction isolation in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AstartTransaction
BinitTransaction
CbeginTransaction
DopenTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'beginTransaction' instead of 'startTransaction'.
Trying to call 'openTransaction' which does not exist.
2fill in blank
medium

Complete the code to commit a transaction in MongoDB.

MongoDB
await session.[1]();
Drag options to blanks, or click blank then click option'
AfinalizeTransaction
BcommitTransaction
CendTransaction
Dcommit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'commit' which is not a method on the session.
Using 'endTransaction' which does not exist.
3fill in blank
hard

Fix the error in the code to abort a transaction in MongoDB.

MongoDB
await session.[1]();
Drag options to blanks, or click blank then click option'
AabortTransaction
Babort
CrollbackTransaction
DcancelTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rollbackTransaction' which is not a MongoDB method.
Using 'abort' without 'Transaction'.
4fill in blank
hard

Fill both blanks to set transaction options for read concern and write concern.

MongoDB
const transactionOptions = {
  readConcern: { level: '[1]' },
  writeConcern: { w: '[2]' }
};
Drag options to blanks, or click blank then click option'
Asnapshot
Bmajority
Clocal
Dlinearizable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' for readConcern in transactions which is weaker.
Using 'linearizable' which is not a valid readConcern level.
5fill in blank
hard

Fill all three blanks to run a transaction with a callback function.

MongoDB
await session.withTransaction(async () => {
  await collection.[1](doc, { session });
  await collection.[2]({ _id: id }, { session });
}, { readConcern: { level: '[3]' } });
Drag options to blanks, or click blank then click option'
AinsertOne
BdeleteOne
Csnapshot
DupdateOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'updateOne' instead of 'deleteOne' for deletion.
Using 'local' instead of 'snapshot' for readConcern.