如何在mongoDB中存储零前导数字

I want to store numbers like 09876 in mongoDb

I'm using php driver and so far I was casting my numbers to (int) , but I just noticed the numbers which starts with Zero , not saving in mongo properly and the zero drops !

So my numbers in mongo are like : NumberLong(9876) but it must be : NumberLong(09876)

So I know I can cast my numbers to String and save them exactly as they are , but is there a way beside this ?

I mean , I dont want to store numbers as Strings in mongo db

something like casting to char ???

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

  1. Store it as text.
  2. Format it before displaying to add the zeroes.