سؤال

I'm using mongodb.

I'm saving a record with a very long number, but I don't want to save it as a number (a float number) I want it as a string.

e.g. I saved "171829572137423434" and I got "1.718295E+16" (just an example) But I need the complete number since is an ID, how can I force to save it as a string in mongodb?

By the way I am using PHP api.

هل كانت مفيدة؟

المحلول

$number = 42;

// this stores as a number
$collection->insert(array('number'=>$number));

// this stores as a string
$collection->insert(array('number'=>strval($number)));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top