Prev Next

Database / MongoDB Interview questions

What does <mongo_db_collection>.watch() command do?

watch function opens a change stream cursor on the collection.

Change streams allow applications to access real-time data changes without any complexity. Applications can use change streams to subscribe to all data changes on a single collection, a database, or an entire deployment, and immediately react to them.

const collection = db.collection('employee');
const changeStream = collection.watch();
changeStream.on('change', next => {
  // process next document
});

More Related questions...

Show more question and Answers...


Comments & Discussions