【发布时间】:2012-01-11 19:37:51
【问题描述】:
我正在尝试使用 pymongo 在 mongodb 中插入一个 64 位无符号整数。该整数是 CRC64 算法的输出。我试图关注:
long(crc64(unicode(kw).encode('unicode-escape'))))
如果我将它插入到 mongodb 中,它开始抱怨 mongodb 只支持 64 位整数。接下来我尝试将其转换为有符号的 64 位 int,如下所示:
ctypes.c_int64(crc64(unicode(kw).encode('unicode-escape')))).value
哪种有效,mongodb 不再抱怨我的 int 的大小,但是当我查看 mongodb 中的数据时,我得到了这个:
{
"_id" : {
"floatApprox" : -5307924876159732000,
"top" : 3059119730,
"bottom" : 2651469802 },
"keyword" : "redacted",
"normal_hash" : {
"floatApprox" : -671156942315906300,
"top" : 4138701393,
"bottom" : 549001936
}
}
这里发生了什么?有什么方法可以将 64 位 int 作为一个 int 放入 db 中(真的不在乎它是带符号的还是无符号的。)
【问题讨论】:
-
你是在 32 位还是 64 位机器上运行 mongo?
-
你试过把它编码成二进制吗?
标签: python mongodb unsigned pymongo