Complete the code to read a document with strong consistency using MongoDB's read concern.
db.collection.findOne({}, {readConcern: {level: '[1]'}})The majority read concern ensures that the read reflects the most recent acknowledged writes, providing strong consistency.
Complete the code to write a document with acknowledged write concern in MongoDB.
db.collection.insertOne({name: 'Alice'}, {writeConcern: {w: [1])Write concern w: 1 means the write is acknowledged by the primary node, ensuring the write is saved.
Fix the error in the code to ensure a read uses linearizable consistency.
db.collection.find({}, {readConcern: {level: '[1]'}})The linearizable read concern guarantees the strongest consistency by reading the most recent acknowledged write.
Fill both blanks to set a write concern that waits for majority and a timeout of 5000ms.
db.collection.updateOne({name: 'Bob'}, {$set: {age: 30}}, {writeConcern: {w: '[1]', wtimeout: [2])Setting w: 'majority' waits for most nodes to confirm the write, and wtimeout: 5000 sets a 5-second timeout for this acknowledgment.
Fill all three blanks to create a read with majority level, a write with w=1, and a write timeout of 2000ms.
db.collection.find({}, {readConcern: {level: '[1]'}}); db.collection.insertOne({item: 'book'}, {writeConcern: {w: [2], wtimeout: [3])The read uses majority for strong consistency, the write uses w: 1 for acknowledgment from primary, and wtimeout: 2000 sets a 2-second timeout.