I'm calling user.save() on an object, where I set user.signup_date = null;
user.first_name = null; user.signup_date = null; user.save();
But when I look at the user in the mongodb it still has the signup_date and first_name set...how do I effectively set this field as empty or null?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With