You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several types of values that will be successfully cast to a Number.
668
+
669
+
```javascript
670
+
newStudent({ id:'15' }).id; // 15 as a Int32
671
+
newStudent({ id:true }).id; // 1 as a Int32
672
+
newStudent({ id:false }).id; // 0 as a Int32
673
+
newStudent({ id: { valueOf: () =>83 } }).id; // 83 as a Int32
674
+
newStudent({ id:'' }).id; // null as a Int32
675
+
```
676
+
677
+
If you pass an object with a `valueOf()` function that returns a Number, Mongoose will
678
+
call it and assign the returned value to the path.
679
+
680
+
The values `null` and `undefined` are not cast.
681
+
682
+
The following inputs will result will all result in a [CastError](validation.html#cast-errors) once validated, meaning that it will not throw on initialization, only when validated:
683
+
- NaN
684
+
- strings that cast to NaN
685
+
- objects that don't have a `valueOf()` function
686
+
- a decimal that must be rounded to be an integer
687
+
- an input that represents a value beyond the bounds of an 32-bit integer
688
+
689
+
667
690
## Getters {#getters}
668
691
669
692
Getters are like virtuals for paths defined in your schema. For example,
0 commit comments