Skip to content

Commit 8ece7d7

Browse files
authored
Merge pull request #15570 from Automattic/vkarpov15/gh-4720
types: support maxLength and minLength in SchemaTypeOptions
2 parents ee6994c + 56be2a7 commit 8ece7d7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/schema/string.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ SchemaString.prototype.trim = function(shouldTrim) {
381381
*
382382
* #### Example:
383383
*
384-
* const schema = new Schema({ postalCode: { type: String, minlength: 5 })
384+
* const schema = new Schema({ postalCode: { type: String, minLength: 5 })
385385
* const Address = db.model('Address', schema)
386386
* const address = new Address({ postalCode: '9512' })
387387
* address.save(function (err) {
@@ -392,8 +392,8 @@ SchemaString.prototype.trim = function(shouldTrim) {
392392
*
393393
* // custom error messages
394394
* // We can also use the special {MINLENGTH} token which will be replaced with the minimum allowed length
395-
* const minlength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
396-
* const schema = new Schema({ postalCode: { type: String, minlength: minlength })
395+
* const minLength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
396+
* const schema = new Schema({ postalCode: { type: String, minLength: minLength })
397397
* const Address = mongoose.model('Address', schema);
398398
* const address = new Address({ postalCode: '9512' });
399399
* address.validate(function (err) {

types/schematypes.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ declare module 'mongoose' {
207207

208208
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at least the given number. */
209209
minlength?: number | [number, string] | readonly [number, string];
210+
minLength?: number | [number, string] | readonly [number, string];
210211

211212
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
212213
maxlength?: number | [number, string] | readonly [number, string];
214+
maxLength?: number | [number, string] | readonly [number, string];
213215

214216
[other: string]: any;
215217

0 commit comments

Comments
 (0)