set field as empty for mongo object using mongoose

To remove those properties from your existing doc, set them to undefined instead of null before saving the doc:

user.first_name = undefined;
user.signup_date = undefined;

user.save();

Confirmed as still working in Mongoose 5.9.7. Note that the field you’re trying to remove must still be defined in your schema for this to work.

Leave a Comment