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
Mongoose supports [64-bit IEEE 754-2008 floating point numbers](https://en.wikipedia.org/wiki/IEEE_754-2008_revision) as a SchemaType.
655
+
Int32s are stored as [BSON type "double" in MongoDB](https://www.mongodb.com/docs/manual/reference/bson-types/).
656
+
657
+
```javascript
658
+
conststudentsSchema=newSchema({
659
+
id: Int32
660
+
});
661
+
constStudent=mongoose.model('Student', schema);
662
+
663
+
conststudent=newTemperature({ celsius:1339 });
664
+
typeofstudent.id; // 'number'
665
+
```
666
+
667
+
There are several types of values that will be successfully cast to a Double.
668
+
669
+
```javascript
670
+
newTemperature({ celsius:'1.2e12' }).celsius; // 15 as a Double
671
+
newTemperature({ celsius:true }).celsius; // 1 as a Double
672
+
newTemperature({ celsius:false }).celsius; // 0 as a Double
673
+
newTemperature({ celsius: { valueOf: () =>83.0033 } }).celsius; // 83 as a Double
674
+
newTemperature({ celsius:'' }).celsius; // null as a Double
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
+
684
+
* strings that do not represent a numeric string, a NaN or a null-ish value
685
+
* numbers in non-decimal or exponential format
686
+
* objects that don't have a `valueOf()` function
687
+
* an input that represents a value outside the bounds of a IEEE 754-2008 floating point
688
+
689
+
651
690
## Getters {#getters}
652
691
653
692
Getters are like virtuals for paths defined in your schema. For example,
0 commit comments