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

153
Vistas
Unable to assign an undefined/null value to an optional property of type Date via Mongoose

I've seen that my updates from a defined value to undefined were not working because of the option omitUndefined: true.

It's works all fine since I removed the option omitUndefined: true.

Expect for the Mongo properties of type Date (which are also optional).

My Mongoose schema contains thoses properties :

tel: { type: String },
dateFin: { type: Date },

On update when I insert a Date value for "dateFin" and a phone object for "tel" :

Console.log results Postman Request

On update when I try to reset their values by putting them to undefined/null :

When I set on Postman, the value null for the properties "tel" and "dateFin" while having omitUndefinied: true as an option in my FindOneAndUpdate Mongoose request :

Console.log results Postman Request

    const data = await this.#db.models.my_table
                .findOneAndUpdate({ _id: obje.id, inactif: undefined }, newData, {
                    new: true,
                    useFindAndModify: false,
                    omitUndefined: true,
                })
                .exec();

When I set on Postman, the value null for the properties "tel" and "dateFin" after removing omitUndefinied: true from the option list of my findOneAndUpdate Mongoose request :

Console.log result Postman request

const data = await this.#db.models.my_table
                .findOneAndUpdate({ _id: obje.id, inactif: undefined }, newData, {
                    new: true,
                    useFindAndModify: false,
                })
                .exec();

I don't know if it can happens for other Mongo/Mongoose type than Date. And I can't find a way out of this situation.

Do you have any ideas please ? Thank you for all your answers !

about 4 years ago · Juan Pablo Isaza
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