Enum and default does not work?

Asked

Viewed 24 times

0

Greetings dev’s, I have the following schema in my app:

const customerModel = new Schema({
    ...
    roles: [{
        type: String,
        required: true,
        enum: ['user', 'admin'],
        default: 'user'
    }]
})

However, when I enter a new System, if I do not pass a value to roles instead of returning the default value = 'user' an empty array is returned.

Data is being saved in a separate file like this:

exports.createCustomer = async (data) => {
    const customer = new Customer(data)

    await customer.save()
}

What I’m doing wrong here ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.