web.onassar.com Archive

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar

-9223372036854775808, NodeJS, Mongo and math

View more posts

Ran into a weird issue today whereby I was accidentally dividing 0 by 0. Normally, your language would/should throw an error, but in JS, you get the number NaN. So fine, I store NaN in Mongo, but what happens when I try and retrieve it. I get the value -9223372036854775808.

It's strange on so many levels. Most notably, that Mongo itself doesn't seem to be the culprit. Running Mongo from command line, storing 0/0 or NaN and retrieving it returns you back NaN. It only seems to return you the fun 0 - 2^63 number when you retrieve it from Node.

The problem is there are so many parts going on at this point. Is it the Node Mongo package? Is it Node itself? I'm not sure, and if I figure it out I'll post, but it seems that NaN/-9223372036854775808 when used with Mongo, Node and JS seem to be synonyms for one-another.