MongoDB BSON provides support for additional data types than
JSON. Drivers provide native
support for these data types in host languages and the
mongo shell also provides several helper classes to support
the use of these data types in the mongo JavaScript
shell. See the Extended JSON
reference for additional information.

The mongo shell provides various methods to return the date,
either as a string or as a Date object:

Date() method which returns the current date as a string.

newDate() constructor which returns a Date object using the
ISODate() wrapper.

ISODate() constructor which returns a Date object using the
ISODate() wrapper.

Internally, Date objects are stored as a 64
bit integer representing the number of milliseconds since the Unix
epoch (Jan 1, 1970), which results in a representable date range of
about 290 millions years into the past and future.

The NumberDecimal() constructor accepts the decimal value as a
string:

NumberDecimal("1000.55")

The value is stored in the database as follows:

NumberDecimal("1000.55")

The NumberDecimal() constructor also accepts double values from
the mongo shell (i.e. without quotes), although this is not
recommended due to the risk of losing precision. The constructor
creates a binary-based double precision representation of the
decimal-based parameter (potentially losing precision), then
converts that value to a decimal value with a precision of 15
digits. The following example passes the value implicitly as a
double and shows how it is created with a precision of 15 digits:

NumberDecimal(1000.55)

The value is stored in the database as follows:

NumberDecimal("1000.55000000000")

The following example passes the value implicitly as a double and
shows how a loss of precision can occur:

NumberDecimal(9999999.4999999999)

The value is stored in the database as follows:

NumberDecimal("9999999.50000000")

Note

To use the decimal data type with a
MongoDB driver, be sure to use a driver
version that supports it.

Values of the decimal type are compared and sorted with other
numeric types based on their actual numeric value. Numeric values
of the binary-based double type generally have approximate
representations of decimal-based values and may not be exactly
equal to their decimal representations, so use the
NumberDecimal() constructor when checking the equality of
decimal values. Consider the following examples with the following
documents in the numbers collection:

The first query, {"val":9.99}, implicitly searches for the
double representation of 9.99 which is not equal to the
decimal representation of the value.

The NumberDecimal() constructor is used to query for the document
with the decimal representation of 9.99. Values of the
double type are excluded because they do not match the exact value
of the decimal representation of 9.99.

Matching values of all numeric types are returned when querying for
whole numbers. For example, querying for a double representation of
10 will include a decimal representation of 10.0 in the
results and vice versa.