Cthoong
Cthoong

Reputation: 63

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 ?

Thanks in advanced.

Upvotes: 3

Views: 2508

Answers (2)

Cthoong
Cthoong

Reputation: 63

  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.

Upvotes: 2

Sammaye
Sammaye

Reputation: 43884

  1. Does it matter if the word "NumberLong" is not being exported ?

Depends, does it matter to you?

The reason why mmongoexport is dong this is because, unlike BSON, JSON does not have the capability to express the advanced objects like NumberLong that BSON can; with this in mind they are simply stripped.

If you intend to import this file back into MongoDB it could matter to you since the objects will be lost.

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

Yes, NumberLong can take a positive integer as its sole parameter.

Upvotes: 0

Related Questions