'How would you store a number larger than the max 64 bit int in mongoDb?
The number is larger than 9223372036854775807 - too big for NumberLong, which is mongo's native 64-bit long type. What's the best way to do this/the best field type?
Is it possible to preserve any of the querying functionality of a smaller integer (such as {$lt}
)?
The big numbers are being generated by bignumber.js, and I'm using mongoose to interact with mongoDb.
Solution 1:[1]
I'm afraid that the only viable/safe option would be to store such big numbers as a string
and serialize it back and forth between the application and MongoDB when read/written. However, you will loose the ability to use MongoDB built-in functions that work with numbers (you can still cast the values to numbers, but it won't be safe anymore).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Slava Fomin II |