【发布时间】:2017-08-22 11:25:09
【问题描述】:
我正在尝试使用 mongoimport 实用程序导入一个 CSV 文件,其中一个特定列的类型为 date-time
从 MongoDB 3.4 版开始,我们可以使用 --columnsHaveTypes 来指示 mongoimport 在 --headerline 中指定的字段列表是特定的输入。
我的 CSV 文件如下所示
TIME,TPS
2006-01-02 07:25:24,1
2006-01-02 07:25:25,2
2006-01-02 07:25:26,2
2006-01-02 07:25:27,2
2006-01-02 07:25:28,2
2006-01-02 07:25:29,2
2006-01-02 07:25:30,1
2006-01-02 07:25:31,3
我已执行但出错的命令
>>mongoimport --db test1 --collection tpsformat --type csv --file C:\ARMS\TestTPS.csv --headerline TIME.date\(2006-01-02 15:04:05\),TPS.string\(\) --columnsHaveTypes --maintainInsertionOrder
2017-08-22T16:36:52.114+0530 error validating settings: only one positional argument is allowed
2017-08-22T16:36:52.119+0530 try 'mongoimport --help' for more information
>>mongoimport --db test1 --collection tpsformat --type csv --file C:\ARMS\TestTPS.csv --headerline TIME.string\(\),TPS.string\(\) --columnsHaveTypes --maintainInsertionOrder
2017-08-22T16:36:59.539+0530 error validating settings: incompatible options: --file and positional argument(s)
2017-08-22T16:36:59.543+0530 try 'mongoimport --help' for more information
但是,没有 --columnsHaveTypes 的简单导入可以正常执行
>>mongoimport --db test1 --collection tpsformat --type csv --file C:\ARMS\TestTPS.csv --headerline --maintainInsertionOrder
2017-08-22T16:37:07.928+0530 connected to: localhost
2017-08-22T16:37:07.936+0530 imported 8 documents
有人可以建议我在这里做错了什么。
谢谢
【问题讨论】:
-
Read the manual "字段名称必须采用
. 的形式。您必须反斜杠转义以下内容如果您希望在参数中包含字符:(、) 和 \."。您的列名不符合该格式。( ) -
--headerline从实际文件中读取。如果您不是这个意思,那么您需要从文件中删除该行并改用--fields。但是你也有错误的格式。而且您不想将任何一个作为“字符串”导入。特别是日期字符串真的很糟糕。 -
@NeilLunn 这两个字段都是必需的格式 TIME.string(),TPS.string() 其中 time =
type = string 并且两个 (, ) 都已使用 \ 进行转义。跨度> -
我已经告诉过你原因了。删除和重新发布您的评论会破坏自然的对话流程。所以不要那样做。就像我说的。手册里有明确的例子,你没有照着做,
-
@NeilLunn 已经删除了 csv 的第一行并且也使用了 --fields ,但这也没有用。如果您发现格式错误,请建议正确的格式吗?
标签: mongodb mongoimport