0
0
MongoDBquery~10 mins

Watch method for real-time updates 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 start watching changes on the collection.

MongoDB
const changeStream = collection.[1]();
Drag options to blanks, or click blank then click option'
Asubscribe
Blisten
Cobserve
Dwatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' or 'observe' which are not valid MongoDB methods.
2fill in blank
medium

Complete the code to handle change events from the change stream.

MongoDB
changeStream.on('[1]', next => {
  console.log(next);
});
Drag options to blanks, or click blank then click option'
Adata
Bchange
Cevent
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' which is a type of change but not the event name.
3fill in blank
hard

Fix the error in the code to properly close the change stream when done.

MongoDB
await changeStream.[1]();
Drag options to blanks, or click blank then click option'
Aclose
Bend
Cstop
Dterminate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stop' or 'end' which are not valid methods on change streams.
4fill in blank
hard

Fill both blanks to filter change events to only insert operations.

MongoDB
const pipeline = [
  { $match: { 'operationType': [1] } }
];
const changeStream = collection.watch(pipeline, { [2]: false });
Drag options to blanks, or click blank then click option'
A'insert'
BfullDocument
Ctrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'true' for fullDocument disables filtering, or wrong operationType string.
5fill in blank
hard

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

MongoDB
const pipeline = [
  { $match: { 'operationType': [1] } }
];
const changeStream = collection.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
DremovedFields
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'removedFields' instead of 'updatedFields' when printing changes.