Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!