0
0
MongoDBquery~10 mins

Transactions vs atomic document writes in MongoDB - Interactive Practice

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

Complete the code to update a single field atomically in a MongoDB document.

MongoDB
db.collection.updateOne({ _id: 1 }, { $set: { status: [1] } })
Drag options to blanks, or click blank then click option'
A"active"
Bactive
Cstatus
D{ active }
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around string values.
Using variable names without quotes.
2fill in blank
medium

Complete the code to start a transaction session in MongoDB.

MongoDB
const session = client.startSession();
session.[1]();
Drag options to blanks, or click blank then click option'
AbeginTransaction
BinitTransaction
CopenTransaction
DstartTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using beginTransaction() which is not a MongoDB method.
Using incorrect method names that do not exist.
3fill in blank
hard

Fix the error in the transaction commit code.

MongoDB
await session.[1]();
Drag options to blanks, or click blank then click option'
AcommitTransaction
Bcommit
CcommitTxn
DendTransaction
Attempts:
3 left
💡 Hint
Common Mistakes
Using commit() which does not exist in MongoDB sessions.
Using incorrect method names like commitTxn().
4fill in blank
hard

Fill both blanks to update two fields atomically inside a transaction.

MongoDB
await collection.updateOne({ _id: 1 }, { $set: { status: [1], count: [2] } }, { session });
Drag options to blanks, or click blank then click option'
A"completed"
B42
C"pending"
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers in quotes.
Forgetting quotes around string values.
5fill in blank
hard

Fill all three blanks to correctly start a transaction, update a document, and commit the transaction.

MongoDB
const session = client.startSession();
try {
  session.[1]();
  await collection.updateOne({ _id: 2 }, { $set: { processed: [2] } }, { session });
  await session.[3]();
} finally {
  await session.endSession();
}
Drag options to blanks, or click blank then click option'
AstartTransaction
Btrue
CcommitTransaction
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for the processed field.
Using wrong method names for starting or committing transactions.