2

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)

Community
  • 1
  • 1
astebbing
  • 21
  • 3

3 Answers3

0

Ah yes. What you probably missed, or didn't fully understand was this line in that post:

DBQuery.shellBatchSize = 500

To explain, that is setting the amount of documents fetched by the cursor in one trip. So a number larger than the default cursor setting which is something like 25.

And here is the real point. He is using a development build to do this, as in the upcoming release aggregate returns a cursor rather than the array of documents that is produced in current releases.

So if you are still interested, you can get a current "release candidate" from the downloads page and that should allow you to reproduce the results.

I didn't quite get there myself (and no more time to play), but it was a matter of setting the terminal columns and rows to something like what was shown on the screenshot in the blog post and zooming out the terminal window in order to reduce the displayed font size.

So it is possible, but you just don't have the same tools installed.

enter image description here

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • Thanks, I forgot to add that I did have `DBQuery.shellBatchSize = 500 ` set. Even if I hadn't I have just got the top part of the image. – astebbing Mar 14 '14 at 09:00
  • @astebbing Yes but the point is you **need** a release that is greater than the 2.4 series in order to have a cursor. Even though you set this value it does nothing for you. – Neil Lunn Mar 14 '14 at 09:14
  • You're correct in surmising that Mr Page is using a development build as he has emailed this morning to say that he is using version 2.5 – astebbing Mar 14 '14 at 09:14
0

You need to use a fixed width font . Each 'pixel' needs to be the same length whether it's '8888' or ' 1'

  • Thanks. I have set the font to fixed with. The output is now rendering horizontally with Mongo version 2.6 but I'm getting the same image as @neillunn below. This is nothing like a proper Manelbrot fractal as per [John Page's original blog post](http://ilearnasigoalong.blogspot.co.uk/2013/12/mongo-aggregating-fractals.html) so I suspect I've got another setting wrong as well seeing as the code is just copy and paste. – astebbing Mar 16 '14 at 12:53
0

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).

mongo aggregation fractal

astebbing
  • 21
  • 3