A. The operationType should be capitalized as 'Insert'
B. The collection name should be user not users
C. You must call start() after watch()
D. The watch method does not accept a filter object directly
Solution
Step 1: Check the argument to watch()
The watch() method expects an array pipeline for filtering, not a direct object.
Step 2: Understand correct filtering syntax
To filter by operationType, you must pass a pipeline like [{ $match: { operationType: 'insert' } }].
Final Answer:
The watch method does not accept a filter object directly -> Option D
Quick Check:
Filter must be pipeline array, not object [OK]
Hint: Use pipeline array for filters in watch() [OK]
Common Mistakes:
Passing filter as object instead of pipeline array
Wrong collection name assumption
Expecting a start() method
Capitalizing operationType values incorrectly
5. You want to build a live notification system that only alerts when a document in the tasks collection is updated and the status field changes to 'completed'. Which change stream pipeline correctly filters these changes?
hard
A. [{ $match: { operationType: 'update', 'updateDescription.updatedFields.status': 'completed' } }]
B. [{ $match: { operationType: 'insert', 'fullDocument.status': 'completed' } }]
C. [{ $match: { 'updateDescription.updatedFields.status': 'completed' } }]
D. [{ $match: { operationType: 'delete', 'updateDescription.updatedFields.status': 'completed' } }]
Solution
Step 1: Identify the operation type needed
We want to watch only updates, so operationType must be 'update'.
Step 2: Filter for status field changed to 'completed'
The updateDescription.updatedFields.status contains changed fields; we check if it equals 'completed'.
Step 3: Combine filters in a pipeline
The correct pipeline is [{ $match: { operationType: 'update', 'updateDescription.updatedFields.status': 'completed' } }].