MongoDB - import CSV into a subdocument

I have a schema with a document structure that looks like this:

{ "_id" : ObjectId( "4f8dcb06ee21783d7400003c" ),
  "venue" : ObjectId( "4f8dcb06ee21783d7400003b" ),
  "name" : "Some event",
  "webite: "www.whatever.com",
  "attendees" : [
                    { "_id" : ObjectId( "4f8dfb06ee21783d7134503a" ), "firstName" : "Joe", "lastName" : "Blogs", "emailAddress" : "some@thing1.com" },
                    { "_id" : ObjectId( "4f8dfb06ee21783d7134503b" ), "firstName" : "John", "lastName" : "West", "emailAddress" : "some@thing2.com" }
                    { "_id" : ObjectId( "4f8dfb06ee21783d7134503c" ), "firstName" : "Simon", "lastName" : "Green", "emailAddress" : "some@thing3.com" }
                    { "_id" : ObjectId( "4f8dfb06ee21783d7134503d" ), "firstName" : "Harry", "lastName" : "Smith", "emailAddress" : "some@thing4.com" }
                ],
  "eventType" : "Party"
}

I have a CSV file that I would like to import into the members collection ...

Is it possible to use mongoimport? I read this: Using mongoimport to read CSV into a nested structure? and it seems that the answer may not be ...

Since this is a one-time operation, would I mind if I had to import it into the collection of "visitors" and then run another command to insert into the collection of visitors in my document? (at the moment there is only one document about the events ...)

+3
source share
2 answers

You are right, and, unfortunately, the answer is no.

Mongoimport - . ( : https://github.com/mongodb/mongo/blob/master/src/mongo/tools/import.cpp) , , , , script, , . , import.cpp , .

+6

, , mongoDB> 4.x

, CSV, .

, extra, , state & creation_at, extra.taxes.auto(), extra.state.auto(), and extra.created_at.date(2006-01-02)

, . , - .

+1

All Articles