问题
I have a number I'm getting from an external source I want to write to the mongo as Int
The problem is that the number is above signed Int64 (which is how mongo implements it) - but is still fits unsinged int64
The number is: 9223372036854776000
How can I still write it to mongo?
I'm getting
OverflowError: MongoDB can only handle up to 8-byte ints
回答1:
With the latest PyMongo and MongoDB 3.4 or later, you can use the standard Python Decimal with the new BSON Decimal128 type.
from decimal import Decimal
from bson.decimal128 import Decimal128
from pymongo import MongoClient
d = Decimal128(Decimal(9223372036854776000))
collection = MongoClient().test.test
collection.insert_one({'myNumber': d})
来源:https://stackoverflow.com/questions/43875204/writing-big-unsigned-int64-to-mongodb-with-pymogno