Reputation: 15329
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
Upvotes: 7
Views: 12755
Reputation: 2523
I realize it has been a while. Posting a solution, hoping it might help someone who landed into this.
Prefixing a command with a void usually silences outputs.
For example, try:
$ mongo <server>/db script.js --eval 'void (yyyymm="2011-11")'
(NOTE: brackets are important)
Upvotes: -1
Reputation: 1433
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
Upvotes: 1
Reputation: 21692
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.
Upvotes: 3