How to add properties to fields with arrays of schemas in mongoose

It took me a while to find this one out, so I’m sharing this tip here with the hope that it might be useful for someone else as well.

Let’s say you have the following mongoose database schema:

const emailSchema = new Schema({
type: {
type: String,
enum: ['Work', 'Personal']
},
email: {
type: String
},
validated: {
type: Boolean,
default: false
}
});
const userSchema = new Schema({
name: { type: String },
emails: [emailSchema]
});