MEAN MongoDB Advanced Operations 5 — Questions and Answers
Question 1: In MongoDB, what is a 'covered query'?
- A query satisfied entirely by an index without scanning the collection documents (Correct answer)
- A query protected by a transaction
- A query that uses an encrypted index
- A query with a projection that includes all fields
Correct answer: A query satisfied entirely by an index without scanning the collection documents
A covered query is one where all fields in the query predicate and projection are part of the same index, so MongoDB never needs to access the actual documents.
Question 2: Which MongoDB aggregation stage is used to add new fields to documents or overwrite existing fields without replacing the entire document?
- $addFields
- $set (alias of $addFields)
- $project
- Both $addFields and $set (Correct answer)
Correct answer: Both $addFields and $set
Both $addFields and $set (its alias introduced in MongoDB 4.2) add or overwrite fields while preserving all other existing fields in the document.
Question 3: What is the default behavior of MongoDB's WiredTiger storage engine regarding data compression?
- Uses snappy compression for collections and zlib for indexes by default (Correct answer)
- All data is stored uncompressed
- Uses zstd for all data by default
- Collections are compressed but indexes are not
Correct answer: Uses snappy compression for collections and zlib for indexes by default
WiredTiger defaults to snappy compression for collection data and prefix compression for indexes, balancing CPU overhead and storage savings.
Question 4: In a MongoDB sharded cluster, what is a 'jumbo chunk'?
- A chunk that exceeds the configured chunk size and cannot be split because all documents share the same shard key value (Correct answer)
- The first chunk assigned to a new shard
- A chunk replicated to all shards
- A chunk that spans multiple config server nodes
Correct answer: A chunk that exceeds the configured chunk size and cannot be split because all documents share the same shard key value
Jumbo chunks occur when a range of shard key values contains too many documents that cannot be further divided, often causing hotspots.
Question 5: What does the MongoDB explain() 'executionStats' verbosity mode return that the 'queryPlanner' mode does not?
- Actual runtime statistics including documents examined and execution time (Correct answer)
- The winning query plan selection only
- Index suggestions for optimization
- All candidate query plans considered
Correct answer: Actual runtime statistics including documents examined and execution time
'executionStats' runs the query and returns real performance metrics like nReturned, totalDocsExamined, and executionTimeMillis.
Question 6: Which MongoDB feature allows you to store encrypted data so that queries can still be performed on ciphertext without decrypting it?
- Queryable Encryption
- Client-Side Field Level Encryption with equality queries
- In-Use Encryption
- All of the above refer to the same feature (Correct answer)
Correct answer: All of the above refer to the same feature
Queryable Encryption, Client-Side Field Level Encryption with equality queries, and In-Use Encryption all refer to MongoDB's ability to query on encrypted data.
Question 7: When using the $lookup aggregation stage with a pipeline sub-query instead of a simple localField/foreignField join, what additional capability does it provide?
- Allows filtering, transforming, and joining on complex expressions rather than just field equality (Correct answer)
- Enables lookups across sharded collections only
- Performs the join in memory using a hash join
- Replaces the need for indexes on the joined collection
Correct answer: Allows filtering, transforming, and joining on complex expressions rather than just field equality
The pipeline form of $lookup lets you specify arbitrary aggregation stages for the joined collection, enabling range queries, $match conditions, and computed joins.
In MongoDB, what is a 'covered query'?