Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
-
None
Description
Description
When we generated change streams examples for the Node.js driver, we provided at least two different approaches: using cursors as an iterator, and using the resulting cursor as an event emitter. The Event Emitter approach is far more idiomatic in node, and I think should be represented in our documentation.
For reference, I'm looking here: https://docs.mongodb.com/manual/changeStreams/
We recommend this as the basic example:
const collection = db.collection('inventory'); |
const changeStream = collection.watch(); |
const next = await changeStream.next(); |
But the preferred form is:
const collection = db.collection('inventory'); |
const changeStream = collection.watch(); |
changeStream.on('change', doc => { |
// process next change document |
});
|