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

238
Vistas
How can I make a mongoDB schema delete in 5 min

So im making a verification code sorta thing, they get the code then they can verify. But, I want to make it so it expires in 5 min (so the db isnt filled with random stuff) after creation how would I go about doing that.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can add expireAt as time-to-live parameter with createIndex.

To create a TTL index, use the createIndex() method on a field whose value is either a date or an array that contains date values, and specify the expireAfterSeconds option with the desired TTL value in seconds.

db.eventlog.createIndex( { "lastModifiedDate": 1 }, { expireAfterSeconds: 3600 } )

Document will expire in 1 hour and will be deleted automatically by mongodb.

Check this documentation | TTL indexes

Update:

In mongoose you can this parameter directly in Schema constructor

const schema = Schema({ name: String, timestamp: Date, metadata: Object }, {
  expireAfterSeconds: 86400
});
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