0
0
MongoDBquery~10 mins

Causal consistency concept 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 enable causal consistency in a MongoDB session.

MongoDB
const session = client.startSession({ causalConsistency: [1] });
Drag options to blanks, or click blank then click option'
Afalse
Btrue
Cnull
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using false disables causal consistency.
Passing null or undefined does not enable causal consistency.
2fill in blank
medium

Complete the code to start a transaction with causal consistency in MongoDB.

MongoDB
session.startTransaction({ readConcern: { level: [1] } });
Drag options to blanks, or click blank then click option'
A"available"
B"local"
C"linearizable"
D"majority"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "local" does not guarantee causal consistency.
Using "linearizable" is stricter but not required here.
3fill in blank
hard

Fix the error in the code to maintain causal consistency when reading after a write.

MongoDB
await collection.insertOne({ name: "Alice" }, { session: [1] });
const doc = await collection.findOne({ name: "Alice" }, { session: [1] });
Drag options to blanks, or click blank then click option'
Aundefined
Bnull
Csession
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Not passing the session to the read operation.
Using different session objects for write and read.
4fill in blank
hard

Fill both blanks to create a session with causal consistency and start a transaction with the correct read concern.

MongoDB
const session = client.startSession({ causalConsistency: [1] });
session.startTransaction({ readConcern: { level: [2] } });
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C"majority"
D"local"
Attempts:
3 left
💡 Hint
Common Mistakes
Setting causalConsistency to false disables causal consistency.
Using "local" read concern does not guarantee causal consistency.
5fill in blank
hard

Fill all three blanks to read a document with causal consistency after a write in the same session.

MongoDB
const session = client.startSession({ causalConsistency: [1] });
await collection.insertOne({ item: "book" }, { session: [2] });
const result = await collection.findOne({ item: "book" }, { session: [3] });
Drag options to blanks, or click blank then click option'
Atrue
Bsession
Cfalse
Dclient
Attempts:
3 left
💡 Hint
Common Mistakes
Not enabling causal consistency in the session.
Using different session objects or none at all.