我试图将数据从 Mongo 导出到 Oracle。我曾经采用以下方法。
Step 1 : Export the data to CS file usign mongoExport command.
Step 2 : Read the data through a java code, do the necessary data transformation.
Step 3 : Insert the data to Oracle
问题是,当任何注释部分有换行符('\n')时,数据将移动到下一行,并且 java read 无法处理文档。
10gen 对此有一个 Unresolved 错误,JIRA 。有没有人遇到过问题。有解决方法吗?
最佳答案
与 CSV 中的许多格式细微差别一样,有 no agreed "standard"了解如何处理 CSV 字段中嵌入的换行符。
常见的实现是 RFC-4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files ,这表明:
6) Fields containing line breaks (CRLF), double quotes, and commas
should be enclosed in double-quotes.
For example:
"aaa","b CRLF
bb","ccc" CRLF
zzz,yyy,xxx
这是 mongoexport
当前使用的格式。如果您使用符合 RFC-4180 的 CSV 解析器(例如 @evanhooly 建议的 SuperCSV),它应该按预期处理引用的换行符。
如果您需要 mongoexport
使用的格式的替代方案,或者需要更灵活的输出,您可以随时编写自己的导出脚本。
关于java - Mongoexport - "\n"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22549363/