0
0
MongoDBquery~10 mins

Change stream pipelines for filtering 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 a change stream that listens for all changes.

MongoDB
const changeStream = collection.watch([1]);
Drag options to blanks, or click blank then click option'
Anull
B{}
C[]
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using an object {} instead of an array []
Passing null or true which are invalid pipeline arguments
2fill in blank
medium

Complete the code to filter change events to only include inserts.

MongoDB
const pipeline = [ { $match: { operationType: [1] } } ];
Drag options to blanks, or click blank then click option'
A'delete'
B'update'
C'replace'
D'insert'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' or 'delete' which filter other change types
Forgetting to put quotes around the string
3fill in blank
hard

Fix the error in the pipeline to filter changes where the field 'status' is 'active'.

MongoDB
const pipeline = [ { $match: { 'fullDocument.status': [1] } } ];
Drag options to blanks, or click blank then click option'
A'active'
Bactive
C"status"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted strings causing syntax errors
Using boolean true instead of the string
4fill in blank
hard

Fill both blanks to filter change events for updates where the 'age' field is greater than 30.

MongoDB
const pipeline = [ { $match: { operationType: [1], 'fullDocument.age': { [2]: 30 } } } ];
Drag options to blanks, or click blank then click option'
A'update'
B'insert'
C$gt
D$lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' instead of 'update' for operationType
Using $lt instead of $gt for greater than comparison
5fill in blank
hard

Fill all three blanks to create a pipeline that filters for delete operations where the document's 'score' is less than 50.

MongoDB
const pipeline = [ { $match: { operationType: [1], 'fullDocument.score': { [2]: 50 }, 'ns.db': [3] } } ];
Drag options to blanks, or click blank then click option'
A'insert'
B$lt
C'myDatabase'
D'delete'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insert' instead of 'delete' for operationType
Using $gt instead of $lt for less than comparison
Not quoting the database name