0
0
MongoDBquery~10 mins

Read concern and write concern in transactions 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 with a read concern of 'majority'.

MongoDB
const session = client.startSession();
session.startTransaction({ readConcern: { level: '[1]' } });
Drag options to blanks, or click blank then click option'
Amajority
Blinearizable
Clocal
Davailable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'local' which reads from the node's local data and may not be majority committed.
Using 'available' which is not a valid read concern level.
2fill in blank
medium

Complete the code to set the write concern to 'w: 1' in a transaction.

MongoDB
session.startTransaction({ writeConcern: { w: [1] } });
Drag options to blanks, or click blank then click option'
Amajority
B0
C1
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using '0' which means no acknowledgment.
Using 'all' which is not a valid write concern value.
3fill in blank
hard

Fix the error in the transaction options to correctly specify read concern level.

MongoDB
session.startTransaction({ readConcern: { level: '[1]' } });
Drag options to blanks, or click blank then click option'
AmajorityLevel
BMAJORITY
Cmajor
Dmajority
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase letters which cause errors.
Using incomplete or incorrect words.
4fill in blank
hard

Fill both blanks to start a transaction with read concern 'snapshot' and write concern 'majority'.

MongoDB
session.startTransaction({ readConcern: { level: '[1]' }, writeConcern: { w: '[2]' } });
Drag options to blanks, or click blank then click option'
Asnapshot
Blocal
Cmajority
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing read concern levels that are not supported in transactions.
Using write concern values that are not strings.
5fill in blank
hard

Fill all three blanks to start a transaction with read concern 'local', write concern '1', and specify a max commit time of 1000 milliseconds.

MongoDB
session.startTransaction({ readConcern: { level: '[1]' }, writeConcern: { w: '[2]' }, maxCommitTimeMS: [3] });
Drag options to blanks, or click blank then click option'
Amajority
B1
C1000
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Using string quotes around maxCommitTimeMS value.
Confusing read concern levels.