MongoDB-将CSV导入嵌套文档 [英] MongoDB - Import CSV into nested document

查看:82
本文介绍了MongoDB-将CSV导入嵌套文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个架构,其文档结构如下所示:

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"
}

我有一个CSV文件,我想将其导入到与会者集合中...

I have a CSV file, that I'd like to import into the attendees collection...

是否可以使用 mongoimport? 我读了这篇文章:使用mongoimport将CSV读取为嵌套结构吗?似乎答案可能不是...

Is that possible using mongoimport? I read this: Using mongoimport to read CSV into nested structure? and it seems as though the answer could be no...

由于这是一次操作,所以我不介意是否必须将其导入到与会者"集合中,然后运行另一个命令以将其插入到文档中的与会者集合中? (目前只有一个事件文档....)

Since this is a one time operation, I wouldn't mind if I had to import it into an "attendees" collection, then run another command to insert into the attendees collection within my document? (there's only one event document at the moment....)

推荐答案

您是正确的,不幸的是,答案是否定的.

You are correct, and unfortunately the answer is no.

Mongoimport是一个非常简单的程序. (您可以在这里亲自查看: https://github .com/mongodb/mongo/blob/master/src/mongo/tools/import.cpp )对于想要导入比二维字符串和数字表更复杂的数据的用户,官方建议编写一个自定义脚本,该脚本将读入您的输入文件并以您想要的格式精确地创建文档.希望import.cpp文件将为您提供一些入门的思路.

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.

这篇关于MongoDB-将CSV导入嵌套文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆