使用mongoimport将CSV读入嵌套结构? [英] Using mongoimport to read CSV into nested structure?
问题描述
我有一个具有如下结构的mongo文档: {foo:{bar1:val1,bar2:val2}}
我想从csv使用 mongoimport --type csv --headerline [...]导入我的数据
I have a mongo document with a structure like: { "foo": { "bar1": "val1", "bar2": "val2"} }
I'd like to import my data from a csv using mongoimport --type csv --headerline [...]
我不知道如何格式化csv中的字段名称来解决嵌套结构。例如:
I am not sure how to format the field name in the csv to address the nested structure. For instance:
test.csv:
foo.bar1
example
返回 {_id:ObjectId(4e9d9d25c5d8708e1f51cdbc ),foo.bar1:example}
而不是所需的输出:
returns { "_id" : ObjectId("4e9d9d25c5d8708e1f51cdbc"), "foo.bar1" : "example" }
instead of the desired output:
{ "_id" : ObjectId("4e9d9d25c5d8708e1f51cdbc"), "foo: {"bar1" : "example"} }
字段名称似乎被解释为一个字符串,不管它的值。 foo [bar1]
和 foo:
The field name seems to be interpreted as a string regardless of its value. Things like foo[bar1]
and foo: {bar1}
are also used verbatim.
推荐答案
目前的版本不支持你可以在这里查看JIRA票,预定为v2.1:
This isn't supported in the current (v2.0) version of mongoimport, but it should be coming soon. You can check out the JIRA ticket here, scheduled for v2.1:
- Dotted field names should produce nested objects in mongoimport
在此之前,如果您可以将CSV数据转换为JSON,那么您可以使用 mongoimport --type json
嵌套数据。
Until then, if you can translate your CSV data to JSON then you could use mongoimport --type json
to import the nested data.
这篇关于使用mongoimport将CSV读入嵌套结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!