Is there a way to force the Mongo shell to output the contents of array sequentially across the page?
Specifically: given an array [8888, 8888, 8888, 8888]
I would like it to render as 8888, 8888, 8888, 8888
and not
"r" : [
8888,
8888,
8888,
8888
]
which is what I keep getting. ( The actual arrays have 84 elements of 8888. I know that this example will print correctly )
Even more specifically, I am trying to get the aggregation code for a Mandelbrot fractal, as published by John Page, to work. The trick is to keep the font size really small. Yet, even with the font size set to 2 and the terminal window set to 1000 columns, the arrays keep getting printed out vertically.
I have done some experiments and, depending on the size of each array element, the character spacing and the font size, a rough guide is that any array where the total number of characters between the square brackets [ ] > 50 or the number of elements > 20 then the arrays print vertically.
I have tried the same experiments in the Terminal bash shell using node.js and this does not happen. So it appears to be a Mongo shell formating problem.
I have tried using DBQuery.prototype._prettyShell = false
as the opposite to this answer for doing pretty printing in the Mongo shell but with no luck.
Mr Page has kindly tested the code again himself and assures me that it works as expected.
For completeness I am running MongoDB shell version: 2.4.9 Terminal Version 2.2.3 (303.2) under Mac OS X 10.7.5
Many thanks
(Note: the original code, as published, had 2 missing opening curly braces in the initial for
loops. I have amended this on my code and it is NOT the cause of the problem. The finally arrays that are produced as a result of the aggregation ARE correct, they just don't render correctly)
To make the code work you need:
MongoDB version 2.5 or higher. As @NeilLunn points out the output requires a cursor so that the resulting arrays are printed across the page.
A fixed width font helps (as @user3420593 notes) but, if your output renders like the image posted by @NeilLunn, then Derick Rethans, a MongoDB PHP specialist, has found a work-round: convert the integer output in the code to strings of 5 characters each '88888' and ' ' (that's 5 spaces between the quotes).