Does MongoDB support floating point types?

前端 未结 4 558
余生分开走
余生分开走 2020-12-03 16:31

I am migrating a mysql database to mongodb. But i have read in MongoDb data types and then there is no reference to floating point types like, float, double, decimal.

<
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 17:22

    MongoDB stores data in a binary format called BSON which supports these numeric data types:

    • int32 - 4 bytes (32-bit signed integer)
    • int64 - 8 bytes (64-bit signed integer)
    • double - 8 bytes (64-bit IEEE 754 floating point)

    There's no exact value fixed-point equivalent to mySQL's decimal type in MongoDB, but you can store 64-bit floating point numbers in Mongo as a double.

    It's worth mentioning that the MongoDB shell - being a JavaScript shell - doesn't recognise the distinction between integer and floating-point values, it treats all numbers the same because JavaScript represents all numbers as 64-bit floating point, regardless of their underlying BSON type.

    Most MongoDB language drivers, however, make the distinction between integer and floating point types.

提交回复
热议问题