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

124
Views
I can't replace the value of an array returned by mongoose

I have a notifications.find query (mongoose) that returns multiple sheets

Notification.find({id: id}, function(err, notifications){}

I need to convert the timestamp values that are returned like that

[                                                                                             
  {
    _id: new ObjectId("12934193c51a231b0165425a"),
    userid: '62921df1c14a2eea0efa9399',
    timestamp: 1653817696599,
  },
  {
    _id: new ObjectId("11934193c51a231b0165425a"),
    userid: '62921df1c14a2eea0efa9399',
    timestamp: 1653817696600,
  }
]

I tried this

notifications.forEach((element, index) => {

notifications[index].timestamp = new Date(notifications[index].timestamp);

});

and this code

new Date(notifications[index].timestamp);

seems to work by converting the timestamp of each value, but I can't replace it in the array

I've been on this issue for several hours

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of forEach use map

const newNotifications = notifications.map((element, index) => {
  return {
    ...element,
    timestamp: new Date(element.timestamp),
   }
});
about 4 years ago · Juan Pablo Isaza 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!