Search code examples
javascriptmongodbmongoosemongodb-querymongoose-schema

Can you use (max / min) on a mongoose string?


Can you use it in this way, so that the maximal string length is 5 Characters, or is this "option" only for Numbers?

  someString: {
    type: String,
    max: 5
  },

Thanks!


Solution

  • No, min/max is for Number and Date. For string, it's minLength/maxLength.

    More info here.