且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OverflowError:MongoDB最多只能处理8字节的整数?

更新时间:2023-11-14 09:51:22

BSON规范 — MongoDB的本机二进制扩展JSON格式/数据类型-仅支持32位(带符号)和64位(带符号)整数-8个字节(即64位).

The BSON spec — MongoDB’s native binary extended JSON format / data type — only supports 32 bit (signed) and 64 bit (signed) integers — 8 bytes being 64 bits.

可以存储在64位int中的最大整数值为: 9,223,372,036,854,775,807

The maximum integer value that can be stored in a 64 bit int is: 9,223,372,036,854,775,807

在您的示例中,您似乎具有较大的ID,例如: 11,611,747,760,398,664,000

In your example you appear to have larger ids, for example: 11,611,747,760,398,664,000

我猜测生成此数据的应用程序正在使用uint64类型(未签名的可以容纳x2-1值).

I’m guessing that the app generating this data is using uint64 types (unsigned can hold x2-1 values).

如果可能的话,我将首先研究以下两种可能的解决方案:

I would start by looking at either of these potential solutions, if possible:

  • 更改另一端以将int64(带符号)类型用于ID.
  • 然后使用 ObjectId()替换传入的ID获取12个字节的〜GUID作为您的唯一ID.
  • Changing the other side to use int64 (signed) types for the IDs.
  • Replacing the incoming IDs using ObjectId() as you then get a 12 byte ~ GUID for your unique IDs.