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

368
Vistas
How to delete this field after 5m automatically on mongoDB ? mongodb, mongoose ,schema

this is my schema i want to automatically expire this field after 5 minutes. how i do that?

const userRegistrationSchema = new mongoose.Schema({

    mobile: {
        type: Number, trim: true,
    },
    email: {
        type: String, lowercase: true, trim: true
    },
    // email Varification
    verified: {
        type: Boolean,
    },
    otp: {
        type: Number,
    },
    password: {
        type: String, trim: true,
    },
    confirmPassword: {
        type: String, trim: true,
    },

if user enter this value and otp store like this

mobile: 9561300851
email: "xyz@gmail.com"
verified: false
otp: 8236

and after 5 minutes i want to my data look like with otp field

mobile: 9561300851
email: "skcoder510@gmail.com"
verified: false

I hope I have explained my problem then how to do it.

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

0

MongoDB supports documents deletion only after a certain time using TTL. However for field deletion what you can do is after using the OTP you can remove the field using $unset.

https://www.mongodb.com/docs/manual/reference/operator/update/unset/

Or, you can create scheduler which will run after certain time and remove all the used OTP field using $unset.

about 4 years ago · Santiago Trujillo Denunciar

0

AFAIK MongoDB only supports TTL on documents, not on fields: https://www.mongodb.com/docs/manual/core/index-ttl/

You could consider creating a separate OTP schema that has a TTL index of 5 minutes. The relevant Mongoose documentation can be found here: https://mongoosejs.com/docs/api.html#schemadateoptions_SchemaDateOptions-expires

about 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