Hi Jose,
The Date.date()
in mongoimport
follows Golang’s date formatting scheme, which is quite different from the typical strftime format that is used in Unix. There are numerous tutorials regarding this unique format, and how to interpret them.
For your specific case, I gathered that the date format should be Date.date(01/02/2006 15:04:05)
, so the full command line is (I renamed everything as test
for testing purposes):
mongoimport --db test --collection test --type csv --columnsHaveTypes --fields="Servername.string(),CPU.int32(),Date.date(01/02/2006 15:04:05)" test.csv
The result of the import:
> db.test.find()
{ "_id" : ObjectId("5e38ee0d5892fa7d14952cbc"), "Servername" : "server1", "CPU" : 10, "Date" : ISODate("2020-01-30T13:38:28Z") }
{ "_id" : ObjectId("5e38ee0d5892fa7d14952cbe"), "Servername" : "server2", "CPU" : 2, "Date" : ISODate("2020-01-30T13:38:28Z") }
{ "_id" : ObjectId("5e38ee0d5892fa7d14952cbb"), "Servername" : "server1", "CPU" : 37, "Date" : ISODate("2020-01-30T13:39:15Z") }
{ "_id" : ObjectId("5e38ee0d5892fa7d14952cbd"), "Servername" : "server2", "CPU" : 2, "Date" : ISODate("2020-01-30T13:39:15Z") }
Best regards,
Kevin