Search code examples
mongodbmongoexport

NumberLong is missing when mongoexport to json file


I used the mongoexport to export a collection to json file (script as below).

mongoexport -d db1 -c user --out /root/user_130226.json

Found that those parameters with type "NumberLong" were saved without word "NumberLong", so when I use mongoimport, the word "NumberLong" is missing too.

Same if using mongodump and mongorestore.

Example:

source :

>> "cd" : NumberLong(1361862291)

output and imported to new collection :

>> "cd" : 1361862291

But if the NumberLong with quote in bracket (), the it exported and imported accordingly.

Example:

"u4" : NumberLong("111018951303058"),

Questions:

  1. Does it matter if the word "NumberLong" is not being exported ?
  2. Is it correct to save the NumberLong without quote ?

Solution

    1. Is it correct to save the NumberLong without quote ?

    It seem like it's the behavior of Mongo, depending on the length of the number. Did further test by parse in different length of number.

    1. 44 - no quote >> NumberLong(44),
    2. 1338585352 - no quote >> NumberLong(1338585352),
    3. 13385853520 - quote added >> "NumberLong("13385853520")
    1. Does it matter if the word "NumberLong" is not being exported ?

    Since with or without quote are correct and it's behavior of Mongo. Hence NumberLong() will be removed when exporting with using mongoexport/mongodump should consider correct too.