Challenge - 5 Problems
Schema Versioning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Output of schema version check query
Given a MongoDB collection
Assuming the collection has 5 documents with
users where each document has a schemaVersion field, what is the output of this query?db.users.find({ schemaVersion: { $lt: 3 } }).count()Assuming the collection has 5 documents with
schemaVersion values: 1, 2, 3, 4, 5.MongoDB
db.users.find({ schemaVersion: { $lt: 3 } }).count()Attempts:
2 left
💡 Hint
Count documents where schemaVersion is less than 3.
✗ Incorrect
Documents with schemaVersion 1 and 2 match the condition, so count is 2.
🧠 Conceptual
intermediate1:30remaining
Choosing a schema versioning strategy
Which schema versioning strategy is best when you want to keep old and new document formats in the same MongoDB collection and handle them differently in your application?
Attempts:
2 left
💡 Hint
Think about how to identify document versions inside the same collection.
✗ Incorrect
Adding a
schemaVersion field allows the application to detect and handle different document formats in one collection.🔧 Debug
advanced2:00remaining
Identify the error in schema migration script
This MongoDB migration script aims to update all documents from schemaVersion 1 to 2 by adding a new field
status with value active. What error will this script cause?db.users.updateMany(
{ schemaVersion: 1 },
{ $set: { status: 'active' }, $inc: { schemaVersion: 1 } }
)Attempts:
2 left
💡 Hint
Check if multiple update operators are combined correctly in one update document.
✗ Incorrect
No error, the script correctly uses multiple update operators ($set and $inc) at the top level of the update document.
❓ optimization
advanced1:30remaining
Optimizing schema version queries
You have a large MongoDB collection with mixed schema versions. You often query documents with
schemaVersion 3. Which index will optimize these queries best?Attempts:
2 left
💡 Hint
Index fields used in query filters for faster lookups.
✗ Incorrect
An index on
schemaVersion speeds up queries filtering by that field.🧠 Conceptual
expert2:30remaining
Handling schema evolution with minimal downtime
What is the best approach to evolve MongoDB document schemas in a live system with zero downtime and backward compatibility?
Attempts:
2 left
💡 Hint
Consider how to keep the system running while supporting old and new data formats.
✗ Incorrect
Using a schemaVersion field allows the application to read and write documents in different formats without downtime.