I'm working on an express API using Mongoose Schema.
When creating for example a "user", I would like to check that my request.body do not contain field that I do not want user to edit.
I was thinking about using the Mongoose schema by adding some custom param, like this:
const schema = new mongoose.Schema({
name: {
type: String,
required: true,
-> input: true
},
email: {
type: String,
required: true,
-> input: true
},
protected_field: {
type: String,
-> input: false
},
...
So based on that login, I would be able to check the request.body of POST /users and return an error in case there is a "protected_field" key inside of it.
Is this possible? Or any better way to achieve it?
Thanks