tags:

views:

51

answers:

1

EDIT: it turns out it's NOT a problem.. pfew! phpMOadmin is not able to display the bigint (probably server apache settings i didn't care).. not mongoDB is unable to save... u.kodingen.com/1fMs5Z i requested from CLI, and it comes back just fine! sorry mongodb.


when i insert tweet to mongodb, it's id e.g. 16906830606 becomes -274549723

our servers are 64bits, I use php mongo driver.

this is the full insert code,

$content = file_get_contents("http://search.twitter.com/search.json?q=worldcup");
$decoded = json_decode($content,true);
  $c = new Mongo("mongodb://x:[email protected]:27017");
  foreach($decoded['results'] as $tweet) 
  {  
    $tweet['_id'] = $tweet['id'];
    $c->db->tweets->insert($tweet);
  }

This is how it saves: http://u.kodingen.com/1fKw6E

If I force it as String,

$tweet['_id'] = "" . $tweet['id'];

then it's correct: http://u.kodingen.com/1fKy8g

I want to know why this happens, and what else I should be worried about MongoDB while you are at it :) just starting out here..

+2  A: 

The _id field, that usually stores an ObjectID, is 12 bytes. A 64-bit integer is 8 bytes. Obviously it has to be converted in some way. As it seems, not in a very good way.

The fact that the timestamp and counter fields must be stored big endian could also be in play.

I would consider not using the tweet id as ObjectID since you can't be certain that they don't add a couple of digits to it tomorrow.

Jonas Elfström
Hi Jonas, thx. it also can't store any big ints in the array either... check in_reply_to_status_id http://u.kodingen.com/1fLW7t i don't want to be checking my array before insertion and cast all integers to strings..
Devrim
Hmm, that's a much worse problem!
Jonas Elfström
it turns out it's NOT a problem.. pfew! phpMOadmin is not able to display the bigint.. not mongoDB is unable to save... http://u.kodingen.com/1fMs5Z i requested from CLI, and it comes back jsut fine!
Devrim
Good! It also seems some (all?) JavaScript-implementations has problems with 64 bit integers.
Jonas Elfström