A change stream is a feature in MongoDB that lets applications listen for real-time changes (like inserts, updates, deletes) happening in the database without polling.
Click to reveal answer
beginner
How do you start watching a change stream on a MongoDB database?
You use the watch() method on the database object to open a change stream that listens to all changes in that database.
Click to reveal answer
intermediate
Which MongoDB operation types can change streams detect?
Change streams can detect insert, update, replace, delete, and invalidate operations.
Click to reveal answer
intermediate
What is the purpose of the resumeToken in change streams?
The resumeToken lets you restart a change stream from a specific point if the stream is interrupted, so you don't miss any changes.
Click to reveal answer
intermediate
Can change streams be used on a single collection, a database, and the entire cluster?
Yes, change streams can be opened on a single collection, on a whole database, or on the entire MongoDB cluster to watch all changes.
Click to reveal answer
What method do you call to start a change stream on a MongoDB database?
Awatch()
Blisten()
Csubscribe()
Dobserve()
✗ Incorrect
The watch() method is used to open a change stream on a database or collection.
Which of these operations will NOT trigger a change stream event?
AcreateIndexes
Binsert
Cupdate
Ddelete
✗ Incorrect
Creating an index does not trigger change stream events; only data changes like insert, update, replace, delete, and invalidate do.
What does the resumeToken help with in change streams?
AFiltering events
BRestarting the stream from a saved point
CEncrypting data
DSorting change events
✗ Incorrect
The resumeToken allows resuming a change stream from where it left off after an interruption.
Can change streams be used to watch changes across all collections in a database?
AOnly on system collections
BNo, only on single collections
CYes, by opening a change stream on the database
DOnly on the cluster level
✗ Incorrect
Opening a change stream on a database watches changes across all its collections.
Which MongoDB feature allows applications to react instantly to data changes without polling?
ASharding
BAggregation pipeline
CIndexes
DChange streams
✗ Incorrect
Change streams provide real-time notifications of data changes without needing to poll the database.
Explain what a MongoDB change stream is and how it can be used in an application.
Think about how apps get notified instantly when data changes.
You got /5 concepts.
Describe the different levels at which you can open a change stream in MongoDB and what each level watches.
Consider the scope of changes you want to monitor.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of MongoDB change streams on databases?
easy
A. To listen for real-time changes in the database
B. To backup the database automatically
C. To create indexes on collections
D. To run queries faster
Solution
Step 1: Understand what change streams do
Change streams allow applications to watch for changes like inserts, updates, or deletes in real-time.
Step 2: Compare options with this purpose
Only To listen for real-time changes in the database describes listening to real-time changes, which matches the main purpose of change streams.
Final Answer:
To listen for real-time changes in the database -> Option A
A. The watch() method cannot be called on a database object
B. The database should be accessed using getSiblingDB('sales') before calling watch()
C. The on() method is not valid for change streams
D. Missing parentheses after watch
Solution
Step 1: Check how the database is accessed
Using db.sales accesses a collection named 'sales' in the current database, not the database itself.
Step 2: Correct way to access a different database
To watch changes on the 'sales' database, use db.getSiblingDB('sales').watch().
Final Answer:
The database should be accessed using getSiblingDB('sales') before calling watch() -> Option B
Quick Check:
Use getSiblingDB to access database, not db.sales [OK]
Hint: Use getSiblingDB('name') to access database, not db.name [OK]
Common Mistakes:
Assuming db.sales is a database instead of a collection
Thinking watch() can't be called on database objects
Confusing event handling methods
5. You want to watch only update operations on the orders database using change streams. Which code snippet correctly applies a filter to achieve this?
hard
A. db.getSiblingDB('orders').watch([{ $match: { operationType: 'update' } }])
B. db.orders.watch({ operationType: 'update' })
C. db.getSiblingDB('orders').watch({ filter: { operationType: 'update' } })
D. db.getSiblingDB('orders').watch([{ $filter: { operationType: 'update' } }])
Solution
Step 1: Recall how to filter change streams
Change streams accept an aggregation pipeline array to filter events, using stages like $match.
Step 2: Apply correct syntax for filtering updates
The correct filter is [{ $match: { operationType: 'update' } }] passed as an array to watch().
Final Answer:
db.getSiblingDB('orders').watch([{ $match: { operationType: 'update' } }]) -> Option A
Quick Check:
Use $match in array to filter change streams [OK]
Hint: Use watch([{ $match: { operationType: 'update' } }]) to filter updates [OK]
Common Mistakes:
Passing filter as object instead of pipeline array
Using invalid keys like 'filter' or '$filter'
Calling watch() on collection instead of database
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.