Numberlong(x) 和 Numberlong(“x") 之间的差异 [英] Diference between Numberlong(x) and Numberlong("x")

查看:55
本文介绍了Numberlong(x) 和 Numberlong(“x") 之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MongoDB 数据库中存储了一些 XML 数据.一些数据存储为 Numberlong(1234),另一些存储为 Numberlong("12353").示例:

I stored some XML data in MongoDB databse. Some of the data is stored as Numberlong(1234) and some other as Numberlong("12353"). Example:

"nodes_id" : [
    NumberLong(13879272),
    NumberLong(252524625),
    NumberLong(252524611),
    NumberLong(252524630),
    NumberLong(149809404),
    NumberLong(605181143),
    NumberLong("3068489546"),
    NumberLong("3059300418"),
    NumberLong(253351454),
    NumberLong(253351438),
    NumberLong(253348623),
    NumberLong(253351472)
]

这两种类型有什么区别吗?

Is there any difference between the two types?

推荐答案

NumberLong(253351454) 仅适用于足够小的数字,它们不需要......: shell 必须以某种方式在 JS 中表示它们,所以它只能表示

NumberLong(253351454) only works for numbers that are small enough that they don't need to be ... well, long: The shell must represent them in JS somehow, so it can only represent numbers that

对于较大的数字,需要文本表示,因为没有足够大的数据类型可用,因此 NumberLong("3059300418")3059300418 >253351454.

For larger numbers, a textual representation is required because there's no large enough data type available, hence NumberLong("3059300418") with 3059300418 > 253351454.

换句话说,不,没有区别.这只是 shell 的限制,或者更一般地说,是 JS 和浮点数的限制.

In other words, no, there's no difference. It's just a limitation of the shell, or more generally speaking, of JS and floating point numbers.

警告:不要尝试用太大的数字调用构造函数,即不要尝试 db.foo.insert({"t" : NumberLong(1234657890132456789)});这个数字对于双精度来说太大了,它会导致舍入错误.上面的数字会被转换成NumberLong("1234657890132456704"),这显然是错误的.

Caveat: Don't try to invoke the constructor with a too large number, i.e. don't try db.foo.insert({"t" : NumberLong(1234657890132456789)}); Since that number is way too large for a double, it will cause roundoff errors. Above number would be converted to NumberLong("1234657890132456704"), which is wrong, obviously.

这篇关于Numberlong(x) 和 Numberlong(“x") 之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆