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 !