Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

316
Vistas
I want to show live data in my node.js app WITHOUT a loop. How do I use mongoDB like Firebase? Is sockets suitable?

A new message gets inserted into the mongoDB from another application that I don't have access to the code. I do have the database credentials though. I want to make that message show on my application at the moment it gets inserted into mongoDB. I don't want to loop. I want to show the new data the moment it gets Inserted or Updated.

A living example: Auction websites generally update the newest bids really quickly, a few seconds before the auction deadline ends. I am wondering how that works without loops. Like a chat app, but waiting for new data in the database instead of another user typing a message. But in my situation, the data gets Inserted or Updated by another application.

Some additional information: I am also using routers / express and hbs html template. I am happy enough if I get atleast a general idea of how to do this, without working with routers / express yet. But if you guys can come up with a combined solution that would be perfect!

I have something like this so far but it's still a bit confusing. You can pretty much ignore my code since it's not working completely. But maybe it helps a bit.

(some more code above ...)    
const WebSocketServer = new WebSocket.Server({port: 8082})

WebSocketServer.on('connection', ws => {
console.log('New client connected!')

ws.on('message', async (data) => {
    console.log(`Client has sent us: ${data}`)

    const connMtlinki = require('../src/db/mtlinki')
    const connection = connMtlinki.connect()
    const database = connMtlinki.db('MTLINKi')

    const MacroVariableHistory = database.collection('MacroVariableHistory')
    const machines = await MacroVariableHistory.findOne({ L0Name: data })

    console.log(machines)

    ws.send(machines)
})

ws.on('close', () => {
    console.log('Client has disconnected!')
})
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda