0
0
MongoDBquery~20 mins

Change stream pipelines for filtering in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Change Stream Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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);
A[{ $match: { 'fullDocument': { $exists: false } } }]
B[{ $match: { 'operationType': { $ne: 'insert' } } }]
C[{ $match: { 'operationType': 'insert' } }]
D[{ $match: { 'operationType': 'update' } }]
Attempts:
2 left
💡 Hint
Look for the operationType field and match it exactly to 'insert'.
query_result
intermediate
2: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 } } }
];
A[{ $match: { 'operationType': 'update', 'fullDocument.status': { $exists: true } } }]
B[{ $match: { 'operationType': 'update', 'updateDescription.removedFields': 'status' } }]
C[{ $match: { 'operationType': 'insert', 'updateDescription.updatedFields.status': { $exists: true } } }]
D[{ $match: { 'operationType': 'update', 'updateDescription.updatedFields.status': { $exists: true } } }]
Attempts:
2 left
💡 Hint
Check the updateDescription.updatedFields object for the changed fields.
📝 Syntax
advanced
2: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 } }
];
A[{ $match: { operationType: 'delete' } }, { $project: { documentKey: 1 _id: 0 } }]
B[{ $match: { 'operationType': 'delete' } }, { $project: { documentKey: 1, _id: 0 } }]
C[{ $match: { operationType: 'delete' } }, { $project: { documentKey: 1, _id: 0 } }]
D]} } 0 :di_ ,1 :yeKtnemucod { :tcejorp$ { ,} } 'eteled' :epyTnoitarepo { :hctam$ {[
Attempts:
2 left
💡 Hint
Look carefully at the commas separating fields inside $project.
optimization
advanced
2: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?
A[{ $match: { operationType: 'update' } }, { $project: { _id: 0 } }]
B[{ $match: { operationType: 'update' } }, { $project: { 'updateDescription.updatedFields': 1, 'documentKey._id': 1, _id: 0 } }]
C[{ $match: { operationType: 'update' } }, { $project: { updateDescription: 1, _id: 0 } }]
D[{ $match: { operationType: 'update' } }, { $project: { fullDocument: 1, _id: 0 } }]
Attempts:
2 left
💡 Hint
Focus on projecting only the changed fields and the document ID.
🧠 Conceptual
expert
3:00remaining
Understanding change stream pipeline behavior with multiple $match stages
Consider this change stream pipeline with two $match stages:
[{ $match: { operationType: 'insert' } }, { $match: { 'fullDocument.status': 'active' } }]

What is the effect of using two separate $match stages instead of combining them into one?
AThe pipeline filters first for inserts, then filters those inserts for documents where status is 'active', effectively the same as a combined $match.
BThe pipeline will fail because multiple $match stages are not allowed in change stream pipelines.
CThe pipeline will return all inserts regardless of status because only the first $match is applied.
DThe pipeline will only filter by the last $match stage, ignoring the first.
Attempts:
2 left
💡 Hint
Think about how MongoDB pipelines process stages sequentially.