SchemaType.cast()

Parameters
  • caster «Function|false» Function that casts arbitrary values to this type, or throws an error if casting failed
Returns:
  • «Function»

Get/set the function used to cast arbitrary values to this type.

Example:

  1. // Disallow `null` for numbers, and don't try to cast any values to
  2. // numbers, so even strings like '123' will cause a CastError.
  3. mongoose.Number.cast(function(v) {
  4. assert.ok(v === undefined || typeof v === 'number');
  5. return v;
  6. });