MongoDB支持浮点类型吗? [英] Does MongoDB support floating point types?
问题描述
我正在将一个mysql数据库迁移到mongodb。但我已经读过MongoDb数据类型,然后没有引用浮点类型,如浮点数,双精度,十进制。
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.
我有一些字段与小数类型在我的sql模式中,我如何做或我能做什么?
And how i have some fields with decimal types in my sql schema , how can i do or what can i do?
推荐答案
MongoDB以二进制格式存储数据 BSON ,支持以下数字数据类型:
MongoDB stores data in a binary format called BSON which supports these numeric data types:
-
int32
- 4个字节(32位有符号整数) -
int64
8位元(64位有符号整数) -
double
- 8个位元组(64位IEEE 754浮点数)
int32
- 4 bytes (32-bit signed integer)int64
- 8 bytes (64-bit signed integer)double
- 8 bytes (64-bit IEEE 754 floating point)
在MongoDB中没有精确的定值等价于mySQL的 decimal
类型,将MongoDB中的64位浮点数存储为 double
。
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
.
值得一提的是,MongoDB shell JavaScript shell - 不识别整数值和浮点值之间的区别,它将所有数字视为相同,因为JavaScript将所有数字表示为64位浮点,而不考虑其底层BSON类型。
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.
但是,大多数 MongoDB语言驱动程序会区分整数类型和浮点类型。
Most MongoDB language drivers, however, make the distinction between integer and floating point types.
这篇关于MongoDB支持浮点类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!