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
The MongoDB Output tool is used for writing data to MongoDB databases. MongoDB is a scalable, high-performance, open source NoSQL database. Learn more about MongoDb. MongoDB databases store data in a binary JSON format called BSON.
You can use mongosh to execute a script from the command line without entering the mongosh console. To specify the filename, use the --file or -f parameter to specify the filename.
In MongoDB, find() method is used to select documents in a collection and return a cursor to the selected documents.
To add output of scripts you must use print()
or printjson()
statements otherwise MongoDB will remain quiet about any output of a 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