0
0
MongoDBquery~10 mins

Session and transaction syntax 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 client session in MongoDB.

MongoDB
const session = client.[1]();
Drag options to blanks, or click blank then click option'
AcreateSession
BbeginSession
CopenSession
DstartSession
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'beginSession' instead of 'startSession'.
Trying to call 'openSession' which does not exist.
2fill in blank
medium

Complete the code to start a transaction inside a session.

MongoDB
session.[1]();
Drag options to blanks, or click blank then click option'
AopenTransaction
BbeginTransaction
CstartTransaction
DinitTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'beginTransaction' which is not a valid method.
Trying 'openTransaction' which does not exist.
3fill in blank
hard

Fix the error in the code to commit a transaction.

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

Fill both blanks to abort a transaction and end the session.

MongoDB
await session.[1]();
session.[2]();
Drag options to blanks, or click blank then click option'
AabortTransaction
BendSession
CcloseSession
DrollbackTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rollbackTransaction' which is not a MongoDB method.
Using 'closeSession' instead of 'endSession'.
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: [2] });
}, { readPreference: [3] });
Drag options to blanks, or click blank then click option'
AinsertOne
Bsession
C'primary'
DupdateOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'updateOne' instead of 'insertOne' for adding a document.
Passing something other than 'session' as the session option.
Using a wrong read preference like 'secondary'.