How do I import a NumberLong
into MongoDB using mongoimport
?
Unfortunately, entries like these in a json file cause an error:
{"_id": NumberLong(123)}
{"_id": NumberLong("123")}
Result:
Mon Nov 12 14:41:46 Assertion: 10340:Failure parsing JSON string near: "_id": Num
0xaf6b21 0xabe459 0xabe5dc 0x7b93ad 0x56160d 0x5630f4 0xabb412 0x5546bc 0x7f961b79776d 0x554549
mongoimport(_ZN5mongo15printStackTraceERSo+0x21) [0xaf6b21]
mongoimport(_ZN5mongo11msgassertedEiPKc+0x99) [0xabe459]
mongoimport() [0xabe5dc]
mongoimport(_ZN5mongo8fromjsonEPKcPi+0x56d) [0x7b93ad]
mongoimport(_ZN6Import8parseRowEPSiRN5mongo7BSONObjERi+0xa2d) [0x56160d]
mongoimport(_ZN6Import3runEv+0x1314) [0x5630f4]
mongoimport(_ZN5mongo4Tool4mainEiPPc+0x1712) [0xabb412]
mongoimport(main+0x2c) [0x5546bc]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7f961b79776d]
mongoimport(__gxx_personality_v0+0x419) [0x554549]
Mon Nov 12 14:41:46 exception:BSON representation of supplied JSON is too large: Failure parsing JSON string near: "_id": Num
Mon Nov 12 14:41:46
Mon Nov 12 14:41:46 imported 0 objects
Mon Nov 12 14:41:46 ERROR: encountered 1 error
Long
value from the java application and read it from database afterwards, Mongo will still return aLong
even when the number fits into regularInteger
. But when I import my data like you suggested, Mongo will not save it asNumberLong
, application will get anInteger
and a nice class cast exception in turn. – Cochineal