Set default to Required for a field in a model in Mongoose?

I'm using Mongoose as a NodeJS client to communicate with MongoDB.

When I was defining my Schema, I found that for most of my fields I'd like to put a "required" validator on it.

I want to check if there're property I can set so that the "validator" is auto put onto a field, when I'm not specifying

required:false

to that field.

Thanks a lot

you can use the 'pre' method : http://mongoosejs.com/docs/api.html#schema_Schema-pre

it allow you to define a function to use before an event.

so you can define a validator before saving and attach it to you schema.

I know it's not attach to a field like you wanted but i hope it can help you