0
0
MongoDBquery~10 mins

Use cases for change streams in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to watch for changes in the 'orders' collection.

MongoDB
const changeStream = db.collection('orders').[1]();
Drag options to blanks, or click blank then click option'
Ainsert
Bfind
Caggregate
Dwatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() instead of watch() to listen for changes.
Trying to use aggregate() without a pipeline for change streams.
2fill in blank
medium

Complete the code to filter change events for only 'insert' operations.

MongoDB
const pipeline = [ { $match: { 'operationType': [1] } } ];
Drag options to blanks, or click blank then click option'
A'delete'
B'insert'
C'update'
D'replace'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' or 'delete' instead of 'insert' for filtering inserts.
Forgetting to put quotes around the operation type.
3fill in blank
hard

Fix the error in the code to properly handle change stream events.

MongoDB
changeStream.on('[1]', next => { console.log(next); });
Drag options to blanks, or click blank then click option'
Achange
Berror
Cdata
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' which is an operation type, not an event name.
Using 'error' which listens for errors, not changes.
4fill in blank
hard

Fill both blanks to create a change stream that watches only 'delete' operations on the 'products' collection.

MongoDB
const pipeline = [ { $match: { 'operationType': [1] } } ]; const changeStream = db.collection([2]).watch(pipeline);
Drag options to blanks, or click blank then click option'
A'delete'
B'insert'
C'orders'
D'products'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' instead of 'delete' for operationType.
Watching the wrong collection name.
5fill in blank
hard

Fill all three blanks to create a change stream that watches 'update' operations and prints the updated fields.

MongoDB
const pipeline = [ { $match: { 'operationType': [1] } } ]; const changeStream = db.collection('users').watch(pipeline); changeStream.on('[2]', change => { console.log(change.updateDescription.[3]); });
Drag options to blanks, or click blank then click option'
A'update'
B'change'
CupdatedFields
D'insert'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' instead of 'update' for operationType.
Listening on 'insert' event instead of 'change'.
Accessing wrong property instead of 'updatedFields'.