Coercion error caused during mongoimport

ID,SUBTYPE,STN,LOC,ENTRY_TIME,EXIT_TIME 
901203311,ADL,82,27,2019-04-01 18:15:05,2019-04-01 18:29:00

The above is part of the csv file that I have. The entry_time and exit_time columns are currently in string format. I tried to use the following code:

mongoimport --db db_name --collection col_name --type csv --columnsHaveTypes --fields "ID.string(),SUBTYPE.string(),STN.int32(),LOC.int32(),ENTRY_TIME.date(2019-04-01 18:15:05),EXIT_TIME.date(2019-04-01 18:15:05)" 

but saw the following error

Failed: type coercion failure in document #1 for column 'ENTRY_TIME', could not parse token '2019-04-01 18:15:05' to type date
2022-03-10T15:18:11.752+0800

Is there any wrong with my code?

@Timmy_Hsu, the following post has couple of solutions for similar import, try that:

https://groups.google.com/g/mongodb-user/c/Cm17SYm0t4s/m/VBWt-fFMAgAJ

I also suggest try without the column names in your CSV file (along with the instructions from the post).

It seems like the problem lies in the .date() part where we have to input 2006-01-02 15:04:05 in particular. After changing into this particular value, the code is working.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.