Search code examples
mongodbcsvimportpymongomongoimport

How do I Import a CSV into a nested document on mongodb


For Example how do I import this

---> test.csv

tesingImport ,hi there

---> What I tried

./mongoimport -d channeladvisor -c products --type csv --file ./test.csv -fields Sku, a.b.c

somehow I get this imported

{
  "_id" : ObjectId("53e6eb0eeb5228df491a0f50"),
  "Sku" : "tesingImport",
  "a.b.c" : "hi there"
}

I can make a script to do this but I wasn't sure if I could use the import to make it faster


Solution

  • Unfortunately, this is not really possible as of MongoDB 2.6. mongoimport is a very simple import program that's not designed to have all the features to support complex import use cases. I recommend that you write your own script to construct the proper documents and insert them into the database.

    There's also an open issue about this capability, SERVER-3691, that you might want to comment on, watch, or upvote.