Speed issue with change streams inside io connection event

Having severe speed issue
with change streams
can anyone help

Using changing streams mongodb inside io.connection which is hugely impacting the socket io performance but want to emit the event to a specific socket id io.sockets.in(socket.id).emit()thats why using it inside :

io.on("connection", async()={ 
const changeStream = await NotificationModel.watch([{
            $match: {
                operationType: { $in: ['insert'] },
            },
        }]);

        changeStream.on('change',
            (event) => {
                if (event.fullDocument.userRef.valueOf() === socket.decoded.data.id) {
                    notifications({
                        id: socket.decoded.data.id,
                    }).then((data) => {
                        io.sockets.in(socket.decoded.data.id).emit('event', { key: data });
                    });
                }
            });
})

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.