How to store zero leading numbers in mongoDB

I want to store numbers like 09876 in mongoDb

I am using a php driver and so far I have cast my numbers to (int), but I just noticed numbers that start with Zero and are not stored in mongo correctly and zero blobs!

So my mongo numbers are similar: NumberLong (9876) , but it should be: NumberLong (09876)

So, I know I can overlay my numbers on String and store them exactly as they are, but is there a way near this?

I mean i dont want to store numbers as strings in mongo db

something like casting to char ???

+3


source to share


1 answer


Numbers are stored as values ​​and any leading zeros will ALWAYS be removed in numeric fields. You have 2 options:



  • Save it as text.
  • Format it before displaying to add zeros.
+2


source







All Articles