Open a change stream on one collection.

Section: Change streams

Watch a collection

javascript
javascript
const stream = db.orders.watch()
Explanation

Change streams let applications react to new writes in near real time.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Change streams
Watch only selected changes
Filter stream events with a pipeline.
OpenIn sheetjavascriptsame section
Read the next change event
Consume the stream in mongosh.
OpenIn sheetjavascriptsame section
Start a session
Create a session for transactional work.
OpenIn sheetjavascript1 tag match
Start a transaction
Begin a multi-document transaction.
OpenIn sheetjavascript1 tag match
Transaction example
Insert and update as one transaction.
OpenIn sheetjavascript1 tag match
Abort a transaction
Roll back a started transaction.
OpenIn sheetjavascript1 tag match