mongodb从宽格式导出到长格式

时间:2014-10-18 08:01:39

标签: mongodb csv export-to-csv dataformat database

mongodb文档结构如下:

1号。

"id" : 1,
"article": "go hiking and bbq",
"category": [
   "travel",
   "hiking",
   "bbq"
]

NO 2。

"id" : 2,
"article": "I love cat and travel",
"category": [
   "pet",
   "cat",
   "travel"
]

当我使用mongoexport将其导出为csv格式时,它会给我一些类似的东西:

id  article                 category
1   go hiking and bbq      ["travel", "hiking", "bbq"]
2   I love cat and travel  ["pet", "cat", "travel"]

这是“宽格式”数据结构

所以,我想知道是否有可能导出为LONG FORMAT,我想打开类别数组,重复每个类别的每篇文章。类似的东西:

id  article                 category
1   go hiking and bbq      "travel"
1   go hiking and bbq      "hiking"
1   go hiking and bbq      "bbq"
2   I love cat and travel  "pet"
2   I love cat and travel  "cat"
2   I love cat and travel  "travel"

或者如果mongodb没有此功能,是否有任何工具可以帮助我将导出的csv文件从宽格式传输到长格式?感谢

====已更新,此处的解决方案====

thx向导。将mongodb更新到2.6.x. 首先聚合到新集合,然后导出收集 参考here

0 个答案:

没有答案