Reputation: 23
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?
Upvotes: 2
Views: 180
Reputation: 46301
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
For larger numbers, a textual representation is required because there's no large enough data type available, hence NumberLong("3059300418")
with 3059300418 > 253351454
.
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.
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.
Upvotes: 1