Why is Firestore rounding 64 bit integers?

拈花ヽ惹草 提交于 2020-05-09 06:22:51

问题


I'm trying to store 64 bit integers from a python program in my Firestore database. The problem is that it seems like the last digits are rounded off.

doc = db.collection('questions').document('0MPvbeTEglD9lbpDq6xm')
ints = [9223372036854775807, 9223372036854775533, 9223372036854775267]
doc.update({
    'random': ints
})

When I look in the database they are stored as:

random = [9223372036854776000, 9223372036854776000, 9223372036854775000}

According to the documentation 64 bit signed integers are supported. What could the problem be?


回答1:


I am not 100% certain, but my guess is that what you're seeing is due to the fact that JavaScript integers are not 64 bits in size. They're actually more like 53 bits. Since the Firebase console is a web app implemented with JavaScript, it probably can't understand the full 64 bits of very large integers you write to it.

What I'd recommend is reading the values back out of your document with another python program instead of checking the values in the console. If they're the same as what you wrote, then there's not real problem here. You just can't trust the rendering of the values in the console.



来源:https://stackoverflow.com/questions/57414755/why-is-firestore-rounding-64-bit-integers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!