0
0
MongoDBquery~20 mins

Read concern levels (local, majority, snapshot) in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Read Concern Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of a query with read concern 'local'

Consider a MongoDB collection orders where a document was just inserted but not yet replicated to secondaries. What will be the result of this query with readConcern: 'local'?

db.orders.find({}).readConcern('local').toArray()
MongoDB
db.orders.find({}).readConcern('local').toArray()
AReturns only documents that are replicated to the majority of nodes
BReturns the newly inserted document immediately, even if not replicated
CReturns documents only from a stable snapshot at the start of the query
DThrows an error because 'local' is not a valid read concern
Attempts:
2 left
💡 Hint

Think about what 'local' means: reading from the node's own data without waiting for replication.

query_result
intermediate
2:00remaining
Effect of read concern 'majority' on query results

In a MongoDB replica set, a document was inserted but has not yet been replicated to the majority of nodes. What will a query with readConcern: 'majority' return?

db.orders.find({}).readConcern('majority').toArray()
MongoDB
db.orders.find({}).readConcern('majority').toArray()
AReturns the document immediately regardless of replication
BReturns an empty array if the document is not replicated yet
CReturns the document only after it is replicated to the majority of nodes
DReturns documents from a snapshot taken at the query start time
Attempts:
2 left
💡 Hint

Consider what 'majority' means for data visibility in a replica set.

query_result
advanced
2:00remaining
Behavior of read concern 'snapshot' in a multi-document transaction

Within a multi-document transaction using readConcern: 'snapshot', what is the visibility of data changes made outside the transaction after it started?

MongoDB
session.startTransaction({readConcern: {level: 'snapshot'}});
db.orders.find({}).toArray();
AThe query sees a consistent snapshot of data as of the transaction start, ignoring outside changes
BThe query sees the latest data including changes made after the transaction started
CThe query fails because 'snapshot' is not allowed in transactions
DThe query returns only documents committed before the last checkpoint
Attempts:
2 left
💡 Hint

Think about what 'snapshot' read concern guarantees inside transactions.

🧠 Conceptual
advanced
2:00remaining
Choosing read concern for low latency vs. data consistency

You want to design a MongoDB application that prioritizes the fastest possible reads, even if it means reading unreplicated or stale data. Which read concern level should you choose?

A'snapshot' because it provides a consistent view of data in transactions
B'majority' because it ensures data is replicated to most nodes before reading
C'linearizable' because it guarantees the most up-to-date data
D'local' because it reads from the node's current data without waiting for replication
Attempts:
2 left
💡 Hint

Consider which read concern returns data fastest without waiting for replication.

🧠 Conceptual
expert
2:00remaining
Impact of read concern 'majority' on read availability during network partitions

During a network partition in a MongoDB replica set, which of the following best describes the behavior of queries using readConcern: 'majority'?

AQueries may block or fail if the node cannot confirm majority replication
BQueries return data from the primary immediately regardless of replication
CQueries return stale data from secondaries without waiting for majority
DQueries automatically downgrade to 'local' read concern to maintain availability
Attempts:
2 left
💡 Hint

Think about how 'majority' read concern depends on replication acknowledgments.