1 year ago
#295707
jack.linton
MongoDB issue with mongoimport of string autoconverting to number
I have a tsv (tab delimited file) with some contact information I want to load into a mongo collection. So I am using mongoimport (which I have to use for reasons I will not go into here, so please don't recommend another way of importing).
I have the telephone number defined as an array by having "telephone.0" in the header line (--headerline).
I use the following command to import the data:
$ mongoimport --db=dbname --collection=colname --type=tsv --headerline --file=datafile.tsv
or
$ mongoimport --db=dbname --collection=colname --type=tsv --headerline --useArrayIndexFields --file=datafile.tsv
I tried both without and with --useArrayIndexFields.
When the telephone number contains special characters like +1 (44) 1234 1234 it reads it in as a string (the way I want it to be read in), but when the telephone number is only a number like 8881112222 it converts it to a NumberLong("8881112222"). If that telephone number would have been 888-111-2222 it would have saved it as a string in the array.
"telephone" : [
NumberLong("8881112222")
]
versus
"telephone" : {
"0" : "888-111-2222"
}
HOW can I tell it to EXPLICITLY save the telephone number as a STRING regardless of the data? Any ideas? Thank you
arrays
mongodb
mongoimport
0 Answers
Your Answer