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

250
Vistas
How to continuously publish the latest N records in Meteor using MongoDB?

I have a piece of code that stores weather information every 30 seconds into a MongoDB collection. I figured out a way to publish the data for the last 24 hours from the server to the client, which goes as follows:

Server

Meteor.publish('mountCarmelData', function dataPublication(){
    return MountCarmel.find({}, 
    {
        limit: 2880//max of 24 hours
    });
});

Client

Meteor.subscribe('mountCarmelData');

If a new record is inserted and the total amount of records in the collection is less than the limit, this new record gets sent to the client automatically. The problem is that when there are more than 2880 records saved in the collection, the new records do not get sent to the client anymore.

I would like to know if there is a way to always send the most recent 2880 records to the client. Or maybe a way to just send the newly inserted record to the client side.

I need the last 24 hours of data to plot in a graph and I need the newly collected data (which is saved into the collection every 30 seconds) to dynamically update the weather variables.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

you need to sort your collection at publish time. i assume you have some kind of time stamp on each record, you can sort by that. e.g.

{
    limit: 2800,
    sort: {createdAt: -1}
}

-1 will sort descending, newest to oldest.

note: this sort is for the publish, to ensure you're publishing the data you want to the client. if your client needs the data in a different order (i.e. descending is not the correct choice there), then the client can sort that published data however it needs to.

over 4 years ago · Santiago Trujillo Denunciar
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