Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo --quiet Not Suppressing --eval output

I'm writing this script that takes in t and uses it in test.js. I'm going to have the output be emailed to me and my collegues.

% mongo my_db --eval 't=9999;' --quiet test.js
9999
------------------------------------------------
Info about stuff going back 9999 days to 2012-08-17.
------------------------------------------------
Stuff x: 433321 (12.43%)
Stuff y: 2723426 (81.57%)
Total: 4524524524

Is there a way to not have what I pass in to --eval be outputted to console so I don't have that dangling '9999' at the top of my results?

Edit: This may be a bug with the --quiet option

See: https://jira.mongodb.org/browse/SERVER-4391

like image 282
doremi Avatar asked Aug 17 '12 14:08

doremi


2 Answers

Bit of a hack, but until that bug gets fixed you could just pipe to tail +2 first and that would exclude the output you do not want, something like:

% mongo my_db --eval 't=9999;' --quiet test.js | tail +2 

This worked for me in a quick test to leave out the 9999 line.

like image 156
Adam Comerford Avatar answered Oct 11 '22 21:10

Adam Comerford


Just in case anybody stumbles over this issue. I had the same problem and got an answer on that solves the problem without shell magic:

Use result from mongodb in shell script

like image 22
Nodebody Avatar answered Oct 11 '22 23:10

Nodebody