Interface MixedSchemaTypeOptions<EnforcedDocType>

Type Parameters

  • EnforcedDocType

Hierarchy

Properties

_id?: boolean

If set, overrides the child schema's _id option. Only allowed for subdocuments and subdocument arrays.

alias?: string | string[]

Defines a virtual with the given name that gets/sets this path.

auto?: boolean

If true, uses Mongoose's default _id settings. Only allowed for ObjectIds

cast?: string | boolean | ((value) => mongoose.Schema.Types.Mixed) | [((value) => mongoose.Schema.Types.Mixed), string] | [((value) => mongoose.Schema.Types.Mixed), ((value, path, model, kind) => string)]

Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message.

Type declaration

default?: any

The default value for this path. If a function, Mongoose executes the function and uses the return value as the default.

enum?: (string | number)[] | readonly (string | number)[] | {
    message?: string;
    values: (string | number)[] | readonly (string | number)[];
} | {
    [path: string]: string | number | null;
}

array of allowed values for this path. Allowed for strings, numbers, and arrays of strings

Type declaration

  • Optional message?: string
  • values: (string | number)[] | readonly (string | number)[]

Type declaration

  • [path: string]: string | number | null
excludeIndexes?: boolean

If true, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.

expires?: string | number

Defines a TTL index on this path. Only allowed for dates.

get?: ((value, doc?) => mongoose.Schema.Types.Mixed)

Type declaration

immutable?: boolean | ((this, doc) => boolean)

If truthy, Mongoose will disallow changes to this path once the document is saved to the database for the first time. Read more about immutability in Mongoose here.

Type declaration

    • (this, doc): boolean
    • Parameters

      • this: any
      • doc: any

      Returns boolean

If truthy, Mongoose will build an index on this path when the model is compiled.

lowercase?: boolean

If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in String#toLowerCase().

match?: RegExp | [RegExp, string] | readonly [RegExp, string]

Attaches a validator that succeeds if the data string matches the given regular expression, and fails otherwise.

max?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string]

The maximum value allowed for this path. Only allowed for numbers and dates.

maxlength?: number | [number, string] | readonly [number, string]

If set, Mongoose will add a custom validator that ensures the given string's length is at most the given number.

min?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string]

The minimum value allowed for this path. Only allowed for numbers and dates.

minlength?: number | [number, string] | readonly [number, string]

If set, Mongoose will add a custom validator that ensures the given string's length is at least the given number.

If set, specifies the type of this map's values. Mongoose will cast this map's values to the given type.

ref?: string | mongoose.Model<any, {}, {}, {}, any, any> | ((this, doc) => string | mongoose.Model<any, {}, {}, {}, any, any>)

The model that populate() should use if populating this path.

Type declaration

    • (this, doc): string | mongoose.Model<any, {}, {}, {}, any, any>
    • Parameters

      • this: any
      • doc: any

      Returns string | mongoose.Model<any, {}, {}, {}, any, any>

refPath?: string | ((this, doc) => string)

The path in the document that populate() should use to find the model to use.

Type declaration

    • (this, doc): string
    • Parameters

      • this: any
      • doc: any

      Returns string

required?: boolean | [boolean, string] | ((this) => boolean) | [((this) => boolean), string]

If true, attach a required validator to this path, which ensures this path path cannot be set to a nullish value. If a function, Mongoose calls the function and only checks for nullish values if the function returns a truthy value.

Type declaration

    • (this): boolean
    • Parameters

      • this: EnforcedDocType

      Returns boolean

select?: number | boolean

Whether to include or exclude this path by default when loading documents using find(), findOne(), etc.

set?: ((value, priorVal?, doc?) => any)

Type declaration

sparse?: number | boolean

If truthy, Mongoose will build a sparse index on this path.

subtype?: number

The default subtype associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths

text?: any

If truthy, Mongoose will build a text index on this path.

transform?: ((this, val) => any)

Type declaration

    • (this, val): any
    • Define a transform function for this individual schema type. Only called when calling toJSON() or toObject().

      Parameters

      Returns any

trim?: boolean

If truthy, Mongoose will add a custom setter that removes leading and trailing whitespace using JavaScript's built-in String#trim().

type: typeof mongoose.Schema.Types.Mixed
unique?: number | boolean

If truthy, Mongoose will build a unique index on this path when the model is compiled. The unique option is not a validator.

uppercase?: boolean

If truthy, Mongoose will add a custom setter that uppercases this string using JavaScript's built-in String#toUpperCase().

Function or object describing how to validate this schematype. See validation docs.

Generated using TypeDoc