MongoDB - Import CSV into nested document

You are correct, and unfortunately the answer is no.

Mongoimport is a very simple program. (You can see for yourself here: https://github.com/mongodb/mongo/blob/master/src/mongo/tools/import.cpp) For users who would like to import data that is more complicated than a 2-dimensional table of strings and numbers, the official advice is to write a custom script that will read in your input file and create documents in exactly the format that you would like them. Hopefully the import.cpp file will give you some ideas on how to get started.


This maybe very late, but will be useful for future users running mongoDB > 4.x

You can have sub-document imported using a csv file by using a dot operator on the name.

for eg. if you want a document with a sub document called extra containing taxes, state & created_at, then you can name your fields as extra.taxes.auto(), extra.state.auto(), and extra.created_at.date(2006-01-02).

I was stuck on this question and couldn't find help online so posting it here. Hope this helps someone.

Tags:

Mongodb