3

enter image description here

What could be the reason that change event is getting called so many times while all I am doing is basic crud on the document ? If change in document then I am refreshing my table by calling serverSideListProject API. and Also, I noticed that connection is getting disconnect frequently, is there any configurations we can make to stop it from disconnecting ? "socket.io": "^2.2.0" for server-side,"ngx-socket-io": "^3.4.0" for client.

app.module.js:

import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';

const config: SocketIoConfig = { url: 'http://localhost:6001', options: {} };


DBHandler code:
exports.monitorChanges = function () {
    return new Promise((resolve, reject) => {
        return getConnection().then((db) => {
            if (db == null) {
                console.log("db in find() is undefined");
                reject();
            } else {

                const changeStream = db.db(config.mongodb.dbname).collection("project").watch(
                    [
                        { $match: { "operationType": { $in: ["insert", "update", "replace"] } } },
                        { $project: { "_id": 1, "fullDocument": 1, "ns": 1, "documentKey": 1 } }
                    ],
                    { fullDocument: "updateLookup" }
                );
                resolve(changeStream)


            }

socket connection:

route.js
var express = require('express');
var app = express();
const io = require('socket.io')();
io.on('connection', socket => {
console.log('connected', socket.id)
socket.on('projects', (data) => projectHandler.serverSideListProject(socket, data));
socket.on('addProject', (data) => projectHandler.addProject(socket, data));
socket.on('updateProject', (data) => projectHandler.updateProject(socket, data));
socket.on('deleteProject', (data) => projectHandler.deleteProject(socket, data));
socket.on('disconnect', () => console.log('A user disconnected'));
});

io.on("connect_error", (err) => { console.log(`connect_error due to ${err.message}`) });
s d
  • 155
  • 14

0 Answers0