How to store unsigned long long (uint64_t) values in a MongoDB document?

痴心易碎 提交于 2019-12-05 09:25:19

With all due respect, IMHO the best thing you can do is to reconsider your decision not to use string for the ID since:

  1. probably it is much more efficient than you ever though due to the amount of overhead of bson internals when storing 64B double which usually is 3 additional fields and field names (see 'floatApprox','top', bottom' here , here and here)

  2. it is already provided as id_str by twitter API you are using for good reason

  3. you are going to have real trouble casting those numbers in JS if you ever happen to use mongodb map reduce

Because MongoDB/BSON only supports signed 64-bit integers, you'll need to cast your 64-bit unsigned values to/from long long when interacting with the database.

All 64-bits are still used so you won't lose any of the available unsigned range, it will just show as a negative value in the database for those values that use the most significant bit.

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