[DOCS-12248] Changestream documents for Node ignores event-based API Created: 07/Dec/18  Updated: 30/Oct/23  Resolved: 15/Jan/19

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: Matt Broadstone Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 5 years, 4 weeks, 1 day ago
Epic Link: DOCSP-1769

 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
});

Scope of changes

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Githook User [ 15/Jan/19 ]

Author:

{'email': 'kay.kim@mongodb.com', 'name': 'Kay Kim'}

Message: DOCS-12248: change streams node examples
Branch: v3.6
https://github.com/mongodb/docs/commit/ca23ff108bb41d713a1207ac48a3d1b5bb4fc3ad

Comment by Githook User [ 15/Jan/19 ]

Author:

{'email': 'kay.kim@mongodb.com', 'name': 'Kay Kim'}

Message: DOCS-12248: change streams node examples
Branch: v4.0
https://github.com/mongodb/docs/commit/102a27967abed1ed07b6a8361154008bd5f60521

Comment by Githook User [ 15/Jan/19 ]

Author:

{'email': 'kay.kim@mongodb.com', 'name': 'Kay Kim'}

Message: DOCS-12248: change streams node examples
Branch: master
https://github.com/mongodb/docs/commit/9ed9284d43638231162981aa49daa8c467b5c8aa

Comment by Kay Kim (Inactive) [ 15/Jan/19 ]

Great. Will publish.

Comment by Matt Broadstone [ 15/Jan/19 ]

kay.kim thanks for pointing that out! It's fixed now in master.

Comment by Githook User [ 14/Jan/19 ]

Author:

{'username': 'mbroadst', 'email': 'mbroadst@gmail.com', 'name': 'Matt Broadstone'}

Message: doc(change-streams): update change streams examples to use streams

Prefer use of streams to iterators, and document both approaches

DOCS-12248
Branch: master
https://github.com/mongodb/node-mongodb-native/commit/78e4c0259bc10c2f8ac3fff5fe7d1cc800cc45e5

Comment by Githook User [ 12/Dec/18 ]

Author:

{'name': 'Matt Broadstone', 'email': 'mbroadst@gmail.com', 'username': 'mbroadst'}

Message: doc(change-streams): update change streams examples to use streams

Prefer use of streams to iterators, and document both approaches

DOCS-12248
Branch: DOCS-12248/update-changestream-docs-for-streams
https://github.com/mongodb/node-mongodb-native/commit/c5361dd331ced6541249f335ff4cc46d8a117b21

Comment by Githook User [ 11/Dec/18 ]

Author:

{'name': 'Matt Broadstone', 'email': 'mbroadst@gmail.com', 'username': 'mbroadst'}

Message: doc(change-streams): update change streams examples to use streams

Prefer use of streams to iterators, and document both approaches

DOCS-12248
Branch: DOCS-12248/update-changestream-docs-for-streams
https://github.com/mongodb/node-mongodb-native/commit/7be54a45c5081247294ac76987c753e8c7a0cb2c

Generated at Thu Feb 08 08:04:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.