Assuming you are referring to Inserting documents using the Atlas UI, a Double
is the equivalent BSON data type to choose for JavaScript’s generic Number
type (a JavaScript Number uses the same 64-bit floating point representation as a BSON Double).
The Atlas user interface uses BSON data types for field selection since they have more granular numeric representation than JavaScript including Int32, Int64, Double, and Decimal128 types.
Typically you would choose the most appropriate data type for your use case. For example, if your values will fit in the range of 32-bit integers (Int32) these use 4 bytes of storage (plus BSON overhead) versus 8 bytes for a 64-bit value. For numeric values requiring precise floating point representation (like currency with fractional values), you would use Decimal128 (which uses 16 bytes).
If you want to validate document inserts/updates using JSON Schema validation, you can either match specific numeric types or use the number
type alias to match any numeric representation while still getting the advantages of appropriate storage size and precision.
Mongoose builds on the extended BSON data type support provided by the official MongoDB Node.js driver & BSON library. The driver provides object wrappers such as Int32
and Decimal128
so extended data types can be created and used from client code where possible. The MongoDB server will save values using the BSON types indicated by the driver.
For one example of how this works in Node.js/Mongoose, see: A Node.js Perspective on MongoDB 3.4: Decimal Type.
Regards,
Stennie