Complete the code to enable causal consistency in a MongoDB session.
const session = client.startSession({ causalConsistency: [1] });Setting causalConsistency to true enables causal consistency for the session.
Complete the code to start a transaction with causal consistency in MongoDB.
session.startTransaction({ readConcern: { level: [1] } });"local" does not guarantee causal consistency."linearizable" is stricter but not required here.Using "majority" read concern ensures causal consistency in transactions.
Fix the error in the code to maintain causal consistency when reading after a write.
await collection.insertOne({ name: "Alice" }, { session: [1] });
const doc = await collection.findOne({ name: "Alice" }, { session: [1] });Passing the same session object to both operations ensures causal consistency.
Fill both blanks to create a session with causal consistency and start a transaction with the correct read concern.
const session = client.startSession({ causalConsistency: [1] });
session.startTransaction({ readConcern: { level: [2] } });"local" read concern does not guarantee causal consistency.Enable causal consistency with true and use "majority" read concern for transactions.
Fill all three blanks to read a document with causal consistency after a write in the same session.
const session = client.startSession({ causalConsistency: [1] });
await collection.insertOne({ item: "book" }, { session: [2] });
const result = await collection.findOne({ item: "book" }, { session: [3] });Enable causal consistency with true and use the same session object for both write and read operations.