mongodb文件中的整数值保存32int。 我想在mongodb中保存64位值。
代码在这里:
import time
import datetime
from pymongo import MongoClient
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.test_database
data = {}
data['num'] = 100
data['createAt'] = datetime.datetime.now()
curTime = datetime.datetime.now()
curTime = int(time.mktime(curTime.timetuple()))
data['time'] = curTime
db.test.insert(data)
结果:
{
"_id" : ObjectId("583420ce7e60a74345c97624"),
"num" : NumberInt(100),
"createAt" : ISODate("2016-11-22T15:41:18.773+0000"),
"time" : NumberInt(1479811278)
}
通缉的结果是:
{
"_id" : ObjectId("583420ce7e60a74345c97624"),
"num" : NumberLong(100),
"createAt" : ISODate("2016-11-22T15:41:18.773+0000"),
"time" : NumberLong(1479811278)
}
存储在NumberInt而不是NumberLong
答案 0 :(得分:2)
您需要使用NumberLong
类型明确创建bson.Int64
变量。
import bson
data['num'] = bson.Int64(100)
答案 1 :(得分:1)