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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With