[MongoDB] Outputting field values containing line breaks in a format that can be imported by Google Spreadsheets
I’ll introduce how to output field values containing line breaks from MongoDB in a format that can be imported by Google Spreadsheets.
Use , (comma) as the delimiter and enclose fields containing line breaks with ” (double quotes).
In the example below, the detail field contains line breaks.
db.products.find( { detail : regExp } ).forEach(function(p){
print(p._id.valueOf() + ',"' + p.detail + '"');
});
Then, execute the script and output the results to a file:
mongo --quiet mydb script.js > example.csv
In Google Spreadsheets, you should be able to import without problems using “Delimiter: Detect automatically”.
That’s all from the Gemba.