Hello, when I’m setting one of the fields of newly created document to be required, when does the mongoose check if it not undefined? Here is my User schema:
const userSchema = new mongoose.Schema({
username: String,
password: String,
tokens: [{
token: {
type: String,
required: true
}
}]
});
Firstly I have created the user instance only with username and password and then i saved him to the database using .save()
method. Only after that I have attached the token to this instace. It didn’t showed any error and everything worked fine, why is that since I have save user instance without required field at the beginning?