Get mongo script shell output

as part of my mongoDB service. I run the mongo shell and load 2 scripts. The command that I run is as follows:

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

The result obtained:

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 redirect the output to a log file, but I would also like to see some output of the loaded scripts. That is, the result that I see in the shell, if I run it, and will call load("...")for the same scripts. Is there a way to capture output?

thank

+5
source share
1 answer

To add script output, you must use instructions print()or printjson(), otherwise, MongoDB will remain silent with respect to any script output.

+11
source

All Articles