Using mongoimport to read CSV into a nested structure?

I have mongo-document with a structure like: { "foo": { "bar1": "val1", "bar2": "val2"} } I would like to import your data from csv, using mongoimport --type csv --headerline [...]

I am not sure how to format the field name in csv to address the nested structure. For instance:

test.csv:

 foo.bar1 example 

returns { "_id" : ObjectId("4e9d9d25c5d8708e1f51cdbc"), "foo.bar1" : "example" } instead of the desired output:

 { "_id" : ObjectId("4e9d9d25c5d8708e1f51cdbc"), "foo: {"bar1" : "example"} } 

The field name is apparently interpreted as a string, regardless of its value. Things like foo[bar1] and foo: {bar1} are also used verbatim.

+6
source share
1 answer

This is not supported in the current (v2.0) version of mongoimport, but it should be available soon. You can check the JIRA ticket here, planned for v2.1:

Until then, if you can convert CSV data to JSON, you can use mongoimport --type json to import the nested data.

+7
source

Source: https://habr.com/ru/post/899535/


All Articles