Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Firestore rounding 64 bit integers?

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?

like image 260
Benjamin Angeria Avatar asked Aug 08 '19 14:08

Benjamin Angeria


1 Answers

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.

like image 70
Doug Stevenson Avatar answered Oct 22 '22 23:10

Doug Stevenson