Mongomapper 中整数的大小
我在 Mongomapper 中找不到整数的限制数。 它可以自动将 MongoDB 中的“大整数”转换为 LongInt 吗?
I couldn`t find the number on limit for the Integer in Mongomapper.
May it convert a 'big integer' to LongInt in MongoDB automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
bson 库为您/mongomapper 处理这个问题。如果您尝试序列化的内容是 bignum/fixnum,它会检查它是否适合 4 字节或 8 字节整数,并相应地对其进行编码。它实际上检查该值,因为 Fixnum 限制与 mongo 具有的 4 字节/字节边界不匹配。
驱动程序的相应位在这里< /a>
The bson library handles this for you / mongomapper. If the thing you are trying to serialise is a bignum/fixnum it checks whether it will fit into a 4 byte or 8 byte integer and encodes it correspondingly. It actually checks the value, since a Fixnum limits don't match the 4 byte /byte boundaries that mongo has.
The corresponding bit of the driver is here
整数数据类型取决于您选择的 Mongo 安装。如果选择 32 位,则整数将达到 32 位,即大约 20 亿。建议选择 64 位安装。
The integer data type depends on the what Mongo installation you chose. If you chose 32 bit, the integer goes up to 32 bits, so about 2 billion. Choosing the 64 bit install is recommended.
MongoDB 以 BSON 格式存储数据(即二进制 JSON)。 BSON 规范支持 32 位和 64 位整数。
这里的关键是您的 Ruby 驱动程序和配置。
MongoDB stores its data in the BSON format (that's binary JSON). The specification for BSON supports both 32-bit and 64-bit integers.
The key here is going to be your Ruby driver and configuration.