Hi MongoDB Community,
I am fairly new to MongoDB. I have been upgrading some 4.4.6 databases to 5.0.1. We have a few Linux bash scripts which use the mongo command and rely on some return code checking in the bash shell which is returned from javscript via the quit() method. I was looking at converting them to use the mongosh command. What I am finding is that the mongosh command doesn’t pass the return code back to the shell.
$ mongo --quiet --host localhost --port 27017 --username userabc -p xxxxxxxx --authenticationDatabase admin << EOF > var rc = 1; > quit(rc); > EOF ================ Warning: the "mongo" shell has been superseded by "mongosh", which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in an upcoming release. We recommend you begin using "mongosh". For installation instructions, see https://docs.mongodb.com/mongodb-shell/install/ ================ $ echo $? 1 $
$ mongosh --quiet --host localhost --port 27017 --username userabc -p xxxxxxxx --authenticationDatabase admin << EOF var rc = 1; quit(rc); EOF test> var rc = 1; 1 test> quit(rc); $ echo $? 0 $
I’ll stick with the mongo command for now but should the return code behaviour be consistent between mongo and mongosh? Or should be be using a different approach for passing return codes back to the bash shell?
Any advice would be greatly appreciated.