0
0
MongoDBquery~10 mins

Transaction performance considerations 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'
AinitTransaction
BbeginTransaction
CstartTransaction
DopenTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist like 'beginTransaction'.
Confusing session start with client start.
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'
Acommit
BsaveTransaction
CfinalizeTransaction
DcommitTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'commit' which is not a method.
Using 'saveTransaction' which does not exist.
3fill in blank
hard

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

MongoDB
await session.[1]();
Drag options to blanks, or click blank then click option'
AabortTransaction
BrollbackTransaction
CstopTransaction
DcancelTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rollbackTransaction' which is not a MongoDB method.
Using 'cancelTransaction' which does not exist.
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'
Amajority
Blocal
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'majority' for read concern which can slow performance.
Using write concern '0' which does not wait for acknowledgment.
5fill in blank
hard

Fill all three blanks to create a transaction with options and start it.

MongoDB
const session = client.startSession();
const options = { readConcern: { level: '[1]' }, writeConcern: { w: '[2]' } };
session.[3](options);
Drag options to blanks, or click blank then click option'
Amajority
B1
CstartTransaction
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' instead of 'majority' for read concern here.
Forgetting to pass options to startTransaction.