When copying and pasting MongoDB query results with tab-delimited strings, tab characters may disappear, so file output is best

Tadashi Shigeoka ·  Tue, May 31, 2016

The other day, a sales employee who can write MongoDB queries consulted me, saying “When I paste Mongo Query output results into Google Spreadsheet, the columns shift to the left, so I’d like a code review.”

MongoDB | モンゴディービー

The conclusion was that there was nothing wrong with the query itself, but when outputting strings delimited by tab characters \t, tab characters can disappear depending on line wrap positions when copying and pasting from Mac’s Terminal app.

Since file output doesn’t cause the problem of disappearing tab characters,

mongo --quiet mydb script.js > example.csv

By outputting to a file like this and importing it into Google Spreadsheet, the columns no longer shift.

If you encounter a similar problem, you might solve it by suspecting the copy-paste behavior from the Terminal app.

That’s all from the Gemba.