I'm trying to import a CSV file using mongoimport but it turns out that the import changes the data itself.
If you have a CSV file like this: (file.csv
)
"SN","Description","OK"
"123456789012345","I should end up in 123456789012345","true"
"1234567890123456","I should end up in 1234567890123456","true"
"12345678901234567","I should end up in 12345678901234567","false"
"123456789012345678","I should end up in 123456789012345678","false"
"1234567890123456789","I should end up in 1234567890123456789","false"
"12345678901234567891","I should end up in 12345678901234567891","false"
"123456789012345678912","I should end up in 123456789012345678912","false"
"1234567890123456789123","I should end up in 1234567890123456789123","false"
And you execute the following commmand:
mongoimport -h XXXXXXX --port=XXXXXXX -u XXXXXXX -p XXXXXXX -vvv --db XXXXXXX --collection XXXXXXX --headerline --type csv --file /path/to/file.csv
You'll end up with strange things in your mongodb database. For instance (a few results shown here):
...
{
_id: ObjectId("56ad7a292e47ad18eb25a405"),
SN: 12345678901234568,
Description: "I should end up in 12345678901234567",
OK: "false"
}, {
_id: ObjectId("56ad7a292e47ad18eb25a406"),
SN: 123456789012345680,
Description: "I should end up in 123456789012345678",
OK: "false"
}, {
_id: ObjectId("56ad7a292e47ad18eb25a407"),
SN: 123456789012345680000,
Description: "I should end up in 123456789012345678912",
OK: "false"
}, {
_id: ObjectId("56ad7a292e47ad18eb25a40b"),
SN: 1.2345678901234568e+21,
Description: "I should end up in 1234567890123456789123",
OK: "false"
}
...
The last number to work was 1234567890123456
So it seems that strings with big numbers on it are transformed into numbers. The problem is the way this is handled, causing unexpected results.
I tried using the following versions of mongoimport:
mongoimport version: 3.0.5 git version: 9da01528ee677e1790bb0b506c816ca9fbe0a6a8
version 2.6.12-pre- (commit b9894192b989d40acdb49aebcb9e64ddf67db1e1)
mongoimport version: 3.2.0-rc5 git version: 6186100ad0500c122a56f0a0e28ce1227ca4fc88
I don't usually use mongoimport but this was supposed to be the easiest way to import some mysql CSV dumps, and it definitely wasn't.