How to listen for updates in mongodb with websockets How to listen for updates in mongodb with websockets database database

How to listen for updates in mongodb with websockets


You can use Change Streams which is supported in many languages.

Since you are using socket.io you can see the node.js implementation

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

Here is the link: https://docs.mongodb.com/manual/changeStreams/