Reputation: 63
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:
Thanks in advanced.
Upvotes: 3
Views: 2508
Reputation: 63
- 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.
- 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
Reputation: 43884
- 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.
- Is it correct to save the NumberLong without quote ?
Yes, NumberLong
can take a positive integer as its sole parameter.
Upvotes: 0