Coercion error caused during mongoimport

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(), 18:15:05), 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

Is there any wrong with my code?

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

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.