Saturday, 24 August 2013

Sort Twitter tweet id string as a number on MongoDB

Sort Twitter tweet id string as a number on MongoDB

I want to store tweets on MongoDB and then find/order them by id, Twitter
API provide two IDs types for a tweet, one as a number type and the other
a string type because JavaScript (mongo/node) can only have 53 bit
integers and Twitter IDs use more than that.
If I store the IDs as numbers the ID get rounded and lost BUT I can sort
and find the IDs with a criteria as "greater than" and "less than".
If I sotre the IDs as strings the ID number get stored as it should BUT I
can't find (select) ids with a criteria of "less than" or "greater than"
and sorting is a mess because it is sorting the "field" as a string, so
"10" shows before "3" because it has "1" at the beginning.
I need to store this IDs and I want to be able to select them with a
criteria as "less/greater/equal/than" and sort them by that "field" as
numbers...
How can I achieve this?
Thanks a lot!

No comments:

Post a Comment