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

123
Vistas
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 Respuestas
Responde la pregunta

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 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