Challenge - 5 Problems
Change Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Filter change stream to only capture insert operations
Given a MongoDB change stream pipeline, which option correctly filters to capture only insert operations?
MongoDB
const pipeline = [ { $match: { 'operationType': 'insert' } } ]; const changeStream = collection.watch(pipeline);
Attempts:
2 left
💡 Hint
Look for the operationType field and match it exactly to 'insert'.
✗ Incorrect
The change stream event document has an 'operationType' field indicating the type of operation. Filtering with $match on 'operationType' equal to 'insert' captures only insert events.
❓ query_result
intermediate2:00remaining
Filter change stream for updates on a specific field
Which pipeline filters a MongoDB change stream to capture only update operations where the field
status was changed?MongoDB
const pipeline = [ { $match: { 'operationType': 'update', 'updateDescription.updatedFields.status': { $exists: true } } } ];
Attempts:
2 left
💡 Hint
Check the updateDescription.updatedFields object for the changed fields.
✗ Incorrect
Update events include an 'updateDescription' field with 'updatedFields' showing which fields changed. Filtering for 'status' in updatedFields captures updates to that field.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this change stream pipeline
Which option contains a syntax error in the MongoDB change stream pipeline?
MongoDB
const pipeline = [ { $match: { operationType: 'delete' } }, { $project: { documentKey: 1, _id: 0 } } ];
Attempts:
2 left
💡 Hint
Look carefully at the commas separating fields inside $project.
✗ Incorrect
Option A is missing a comma between 'documentKey: 1' and '_id: 0' inside the $project stage, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimize change stream pipeline to reduce unnecessary data
Which pipeline best optimizes a change stream to only return the
_id and changed fields for update operations?Attempts:
2 left
💡 Hint
Focus on projecting only the changed fields and the document ID.
✗ Incorrect
Option B projects only the updated fields and the document's _id, minimizing data sent and improving efficiency.
🧠 Conceptual
expert3:00remaining
Understanding change stream pipeline behavior with multiple $match stages
Consider this change stream pipeline with two $match stages:
What is the effect of using two separate $match stages instead of combining them into one?
[{ $match: { operationType: 'insert' } }, { $match: { 'fullDocument.status': 'active' } }]What is the effect of using two separate $match stages instead of combining them into one?
Attempts:
2 left
💡 Hint
Think about how MongoDB pipelines process stages sequentially.
✗ Incorrect
MongoDB pipelines process stages in order. Multiple $match stages filter data step-by-step, so two $match stages filter first by operationType, then by status, same as combining conditions in one $match.