In my user schema I have a property:
verification: {
phoneVerification: {
verified: Boolean,
code: String,
},
however, if I change it to this:
verification: {
phoneVerification: {
verified: Boolean,
code: String,
carrier: String,
type: String
},
It changes my Javascript output which ends up causing an error for me.
let user = await User.findOne({ _id: req.user._id }, '-salt -password').exec();
user.verification.phoneVerification = {};
console.log(user.verification);
This code at first outputs:
{ phoneVerification: null,
mailVerification: { verified: false, code: '1c7d55d3d2e64ae98e82' } }
Then ends up outputting:
{ mailVerification: { verified: false, code: '1c7d55d3d2e64ae98e82' } }
After my model has been changed.
Because of the fact that phoneVerification isn't instantiated, my code is giving me back an error.
It's very weird, what is causing this to happen?
Edit:
I'm asking why adding another subproperty to the property on the user model, I can no longer instantiate this verification.phoneVerification object to eventually save properties to it. It's not a duplicate of above question.