8

as a part of my mongoDB maintenance I'm running mongo shell and make it to load 2 scripts. The command I'm running looks like follows:

$MONGO_HOME/bin/mongo --verbose --port 27017 replSetConfig.js initializeReplicaSet.js

The output I got is:

MongoDB shell version: 2.2.3
Thu Mar  7 03:00:00 versionCmpTest passed
Thu Mar  7 03:00:00 versionArrayTest passed connecting to: 127.0.0.1:27017/test
Thu Mar  7 03:00:01 creating new connection to:127.0.0.1:27017
Thu Mar  7 03:00:01 BackgroundJob starting: ConnectBG
Thu Mar  7 03:00:01 connected connection!
loading file: js/replSet.config.js
loading file: js/initializeReplicaSet.js

I'm redirecting the output to a log file but I would like to see some output of the loaded scripts as well. I.e. the output which I see in the shell if I start it and call load("...") for the very same scripts. Is there a way how to capture the output?

Thanks

3
  • 1
    I guess I didnt get the question right. But I use printjson() within the mongoscript files for logging. Commented Mar 7, 2013 at 11:02
  • It looks like it'll be where I'll end up ... It is suitable for some situations but I don't see how would I log e.g. the rs.intitate() command which I'm calling in the script ... ? This is what I'm calling in the script and I don't see a way how to get the result. I can log rs.status() after the command but in won't tell WHY it failed (if it failed) Commented Mar 7, 2013 at 11:05
  • 1
    To get the output of a script you must specify print() or printjson() statements otherwise MongoDB will stay silent. Commented Mar 7, 2013 at 11:39

1 Answer 1

15

To add output of scripts you must use print() or printjson() statements otherwise MongoDB will remain quiet about any output of a script.

Sign up to request clarification or add additional context in comments.

1 Comment

Ha, found that you can actually do printjson( rs.initiate(config) ); for example so this is actually what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.