Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
mongoDB changestream emitting multiple times nodejs

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}`) });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda