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

228
Views
How to obtain data from mongoose collection according to week month or years? P.S every document is stored or updated as a single document for a day

I have to show a chart in frontend which takes an array of numbers (7 for a week, 12 for months and 5 for years as shown as shown in the image). Week Month Year In backend I had a document for everyday which stores and updates on daily basis as unique for a day storing total energy delivered. Currently I have timestamps in epoch time but I can change it to anything which fulfils my needs.

I want to write queries for obtaining data based on selection using bPID. Suppose I select week it queries last 7 document for a particular bPID and return it to me so that I can filter it out. Suppose I select months so it returns me 31 collections for Jan and 28 for Feb which I would process it in my backend and get an array of 12 for a month. How to query this so that in the end I end up getting array of 7 documents for a week, 12 for a month, 5 for a year.

My current collection:

const analyticSchema = new Schema(
  {
    bPID: String,           // unique for every document
    todaysTimeStamp: Number,  // epoch time for 12:00 am 
    energyConsumed: Number
  },
  {
    timestamps: true
  }
);
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can get last 7 document for a week, for months you have to query based on this month and get last 365/366 documents. Filter it out based on months. For years you have to get it as mentioned above.

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!