MongoDB inserts float when trying to insert integer

前端 未结 4 1192
小蘑菇
小蘑菇 2020-12-12 13:08
   > db.data.update({\'name\': \'zero\'}, {\'$set\': {\'value\': 0}}) 
   > db.data.findOne({\'name\': \'zero})
    {\'name\': \'zero\', \'value\': 0.0}  
         


        
4条回答
  •  离开以前
    2020-12-12 13:37

    Well, it's JavaScript, so what you have in 'value' is a Number, which can be an integer or a float. But there's not really a difference in JavaScript. From Learning JavaScript:

    The Number Data Type

    Number data types in JavaScript are floating-point numbers, but they may or may not have a fractional component. If they don’t have a decimal point or fractional component, they’re treated as integers—base-10 whole numbers in a range of –253 to 253.

提交回复
热议问题