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

534
Vistas
What is the best way to notify users that document expired in database?

In my application users create documents which are then saved in the database. The document has expireAt field which is set to 30 days ahead from the date it is created. After the expiration date the document is considered as inactive.

So, what I want is to send an email to the user after expiration date to notify him that his document is now inactive. The only solution I see is to create a cron job and periodically poll the database for expired documents.

But I'm not sure if periodical polling is a good approach and would like to know if there are other ways of doing this.

P.S. The app is built with nodejs + mongoDB

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Tykaty, you can try to use 2 features of mongodb:

  • Expire data https://docs.mongodb.com/manual/tutorial/expire-data/
  • Change events https://docs.mongodb.com/manual/reference/change-events/ https://docs.mongodb.com/manual/changeStreams/#watch-a-collection--database--or-deployment

The idea is simple. You store the documents as before. Add a collection that you will watch and add there objects which should expire, link each document in your original collection to a corresponding object to be expired(1 to 1 link). When the object is deleted by mongo engine(expired), you get a notification with it's _id. Find this _id in your original collection of documents to understand which doc was expired. Here you are.

Of course, you can start with polling, final solution depends on the data and it's usage, the load as well.

over 4 years ago · Santiago Trujillo Denunciar

0

If your use case is just removing the expired doc, you could use TTL feature of mongodb.

Since you need to send an email, the best option is cron job as you already thought of. Yes, periodically polling is a good option and works in most of the use cases and you do have control over it.

As per your requirement, you could poll once per day. If you are still need to care till minute level of expiry, you could do that by subtracting 24 hours from your actual query and send an alert for user convenience.

over 4 years ago · Santiago Trujillo 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