Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
838 views
in Technique[技术] by (71.8m points)

database - Does MongoDB support floating point types?

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.

And how i have some fields with decimal types in my sql schema , how can i do or what can i do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...