Why is Firestore rounding 64 bit integers?

Posted on

Question :

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]
    '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?

Answer #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.

Answered By: Doug Stevenson

Leave a Reply

Your email address will not be published. Required fields are marked *