Skip to content

Latest commit

 

History

History
17 lines (12 loc) · 836 Bytes

custom-casting.md

File metadata and controls

17 lines (12 loc) · 836 Bytes

Custom Casting

Mongoose 5.4.0 introduced several ways to configure SchemaTypes globally. One of these new features is the SchemaType.cast() function, which enables you to override Mongoose's built-in casting.

For example, by default Mongoose will throw an error if you attempt to cast a string that contains a Japanese numeral to a number.

[require:custom casting.*casting error]

You can overwrite the default casting function for numbers to allow converting the string that contains the Japanese numeral "2" to a number as shown below.

[require:custom casting.*casting override]