【问题标题】:How do I merge csv to a collection using mongoimport如何使用 mongoimport 将 csv 合并到集合中
【发布时间】:2019-05-12 18:04:42
【问题描述】:

我正在尝试使用命令将 csv 导入到我的 mongodb 集合中

mongoimport --mode 合并 --headerline --upsertFields 名字 --db Intelligense --collection 演示 --file demo.csv --type csv

但得到

error inserting documents: An empty update path is not valid.

我做错了什么?

我在数据库“Intelligense”下有一个集合“demo”,其中包含格式的数据

{ 
    "_id" : ObjectId("5cd8559c041f762929f36d97"), 
    "firstname" : "john", 
    "lastName" : "mayer"
}

我的 csv 包含

_id, email, firstname 5cd8559c041f762929f36d97,johnmayer@gmail.com, john

我想实现以下集合作为最终结果

{ 
    "_id" : ObjectId("5cd8559c041f762929f36d97"), 
    "firstname" : "john", 
    "lastName" : "mayer",
    "email" : johnmayer@gmail.com
}

【问题讨论】:

  • 请问您使用的是哪个 mongo 版本?我刚刚在 3.6 上模拟了您的场景,效果很好。
  • 您是否为演示集合定义了任何架构验证?

标签: python mongodb csv merge mongoimport


【解决方案1】:

我找到了答案。问题是我的 csv 文件中没有标题的索引列无效。

【讨论】:

    猜你喜欢
    • 2015-07-20
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    相关资源
    最近更新 更多