简体   繁体   中英

Creating Mongoose Schema with parameter validation

I am trying to create a simple user schema with mongoose and i want to validate some of my fields. It is not clear to me what validation is available to me when reading the documentation, i am wondering if someone can point me in the right direction where to read about all validation options available to me?

const UserSchema = new Schema({
  email: {
    type: String,
    required: true,
    unique: true,
    trim: true,
  },
  password: {
    type: String,
    required: true,
  },

});

For example, i would like to know if i can declare minimum character length on my email property. I know this can be done with maxChar: etc. or something but i cant find the part in their documentation where it talks about this?

After some writing this question i finally found the part in mongoose documentation that i was looking for.

Here is the part about the validation parameters available to mongoose Schemas https://mongoosejs.com/docs/schematypes.html#strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM