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

491
Views
¿Cómo puedo eliminar un objeto completo de una matriz antes de su fecha de caducidad en mongoose?

Doc:

 "notifcations": [ { "title": "Joined the Tournament.", "description": "You have registered in the Tournament of Tournament #142, issued ₹10 from your balance.", "amount": 10, "createdAt": "2022-05-08T12:03:02.431Z", "expiresAt": "2022-05-09T12:03:05.983Z", "_id": "6277b17968729c2811137fb0" }, { "title": "Joined the Tournament.", "description": "You have registered in the Tournament of Tournament #143, issued ₹10 from your balance.", "amount": 10, "createdAt": "2022-05-08T12:03:02.431Z", "expiresAt": "2022-05-09T12:03:05.983Z", "_id": "6277b17968729c2811137fb0" } ]

Aquí, en la matriz de notificaciones, quiero eliminar todos los objetos que están vencidos: "expiresAt" en el objeto. Me gusta eliminar todos los objetos en los que expiresAt < Date.now()

La matriz de notificaciones está almacenada en mongodb y quiero crear una función para eliminar las notificaciones caducadas.

¿Alguna ayuda por favor?

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

0

Probablemente el método más simple sería usar Array.filter()

 const myObj = { "notifcations": [ { "title": "Joined the Tournament.", "description": "You have registered in the Tournament of Tournament #141, issued ₹10 from your balance.", "amount": 10, "createdAt": "2021-05-08T12:03:02.431Z", "expiresAt": "2021-05-08T12:03:05.983Z", "_id": "6277b17968729c2811137fb0" }, { "title": "Joined the Tournament.", "description": "You have registered in the Tournament of Tournament #142, issued ₹10 from your balance.", "amount": 10, "createdAt": "2022-05-08T12:03:02.431Z", "expiresAt": "2022-05-09T12:03:05.983Z", "_id": "6277b17968729c2811137fb0" }, { "title": "Joined the Tournament.", "description": "You have registered in the Tournament of Tournament #143, issued ₹10 from your balance.", "amount": 10, "createdAt": "2022-05-08T12:03:02.431Z", "expiresAt": "2022-05-09T12:03:05.983Z", "_id": "6277b17968729c2811137fb0" } ] }; myObj.notifcations = myObj.notifcations.filter(a => new Date(a.expiresAt) > new Date()); console.log(myObj);

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!