VenkatMSN
(Venkat M S N)
August 31, 2022, 9:43am
1
In CSV import, on the 1st line, if i remove the column types, it imports just fine. Else it creates weird documents.
Example1: when CSV file has firstName.string(),lastName.string(),email.string() and 1 row of data:
Resulting Document is
{
"_id" : ObjectId("630f28b72e83ac2a6aa5a0ec"),
"firstName" : {
"string()" : "John"
},
"lastName" : {
"string()" : "Doe"
},
"email" : {
"string()" : "john@doe.com"
}
}
If I remove the column types, and do the CSV import, then resulting document is
{
"_id" : ObjectId("630f29402e83ac2a6aa5a0fb"),
"firstName" : "John",
"lastName" : "Doe",
"email" : "john@doe.com"
}
The thing is i don’t care about the string type but for many other imports, i want to specify, boolean, timestamp, date, etc.
Has this changed in recent versions of mongo? This used to work earlier. I couldn’t find coumentation on this, hence asking
Thanks
Stennie_X
(Stennie)
September 1, 2022, 1:33am
2
Welcome to the MongoDB Community @VenkatMSN !
What does mongoimport --version
report and what command line parameters are you using?
You can specify field types with --columnsHaveTypes
and would also need --headerline
if the source of types is the first row in your CSV file.
I created a test CSV with:
firstName.string(),lastName.string(),email.string()
John,Doe,john@doe.com
… and imported using:
mongoimport --columnsHaveTypes --headerline test.csv --type csv -d foo -c bar
The resulting document is:
{
_id: ObjectId("6310098a14219fbdb46a04c5"),
firstName: 'John',
lastName: 'Doe',
email: 'john@doe.com'
}
I believe your command line is missing the --columnsHaveTypes
parameter, so the types in the header line will be interpreted as field names (which would be embedded documents using dot notation ).
Regards,
Stennie
1 Like
VenkatMSN
(Venkat M S N)
September 1, 2022, 8:18am
3
Ugggh…
Thanks! I was importing directly on Atlas etc and when i had used the import tool on a shell, I had only /headerline and not the columns have types.
Problem Solved
Thanks!
1 Like
system
(system)
Closed
September 6, 2022, 8:19am
4
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.