使用ISODate导入CSV文件MongoDB

勒丘奇科

当我从mongoDB导出数据时,我获得以下文件:

除了日期ISODate之外,所有内容都是mongoDB中的字符串。

[email protected],sha1:64000:18:BTJnM903gIt5FNlSsZIRx1tLC9ErPJuB:9YVs800sgRPr1aaLj73qqnJ6,123,123,[email protected],2017-04-28T09:20:07.480Z,cus_AYcVXIUf68nT52

如果我将此文件导入MongoDB,它将每个值作为String值导入。我需要将日期解析为日期格式,其余的可以是字符串。

我已经看到MongoImport --columnsHaveTypes有一个参数。我尝试了没有任何结果:

mongoimport -u test-p test --authenticationDatabase test -h localhost:30158 --db test--collection users --type csv --file users.csv --upsert --upsertFields username --fields username.string\(\),password.string\(\),cname.string\(\),sname.string\(\),mail.string\(\),creation.date\(\),validation.auto\(\),clients.string\(\),customer.string\(\) --columnsHaveTypes

我收到此错误:

Failed: type coercion failure in document #0 for column 'creation', could not parse token '2017-04-28T09:20:07.480Z' to type date

我能做什么?

亲切的问候。

文斯·鲍德伦(Vince Bowdren)

摘要:您需要提供显示日期的格式。

从mongoimport文档的columnHaveTypes参数上,您不能仅仅说created.date\(\)-您需要提供一个参数,该参数是CSV中日期表示方式的模板。显然,按照Go Language time.Parse函数,您可以通过以您选择的格式呈现特定的参考日期来执行此操作。

我认为参考日期应采用以下格式:

2006-01-02T15:04:05.000Z

因此,您需要更改mongoimport调用以使用格式模板指定日期,如下所示:

creation.date\(2006-01-02T15:04:05.000Z\)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章