问题描述
MongoDB中的double,NumberLong,NumberInt或简单Integer数据类型之间的主要区别(大小,速度等)是什么?
What are the main differences (size, speed, etc) between the datatypes double, NumberLong, NumberInt or a simple Integer in MongoDB?
如果我想保存一个小的固定数字(0到1000之间),应该使用哪种数据类型?
If I want to save a small fixed number (something between 0 and 1000) which data type should I use?
推荐答案
NumberInt
默认情况下,mongo shell将所有数字视为浮点值. mongo shell提供了NumberInt()
构造函数来显式指定32位整数.
By default, the mongo shell treats all numbers as floating-point values. The mongo shell provides the NumberInt()
constructor to explicitly specify 32-bit integers.
NumberLong
默认情况下,mongo shell将所有数字视为浮点值. mongo shell提供了NumberLong()
类来处理64位整数.
By default, the mongo shell treats all numbers as floating-point values. The mongo shell provides the NumberLong()
class to handle 64-bit integers.
NumberLong()
构造函数接受long作为字符串:
The NumberLong()
constructor accepts the long as a string:
NumberLong("2090845886852")
来源: http://docs.mongodb.org/manual/core/shell -types/
这篇关于MongoDB NumberLong和简单整数之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!