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

257
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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