We are currently upgrading from 4.4 to 5.0. Our Installation scripts have a lot of mongo commands that runs and evaluates the output. Due to the deprecation of mongo, we tried to migrate our scripts to use mongosh. However, we are running into issues due to the output mismatch between two.
Here is the difference between two outputs. As you can see below, mongo returns the results which is the number of documents from a collection, where as mongosh is returning connectivity strings along with some other things. I tried various options to figure out hwo to get it back to the original mongo. We have a lot of scripts that use mongo + quiet + eval. I am hoping there is an easy way to fix this issue.
How do I go about making mongosh not print the connectivity information in the result. As you
>>docker exec -it d58a07d2fbe1 mongo --quiet -host 127.0.0.1:27017 testmongosh.js | cat -v
0^M
>>$ docker exec -it d58a07d2fbe1 mongosh --quiet -host 127.0.0.1:27017 testmongosh.js | cat -v
^[]0;mongosh mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000^G^[[1G^[[0J ^[[1G^[[33m0^[[39m^M
0^M ( all our code is scripted to expect just return from js) - And mongosh is returning : ^0;mongosh mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000^G^[[1G^[[0J ^[[1G^[[33m0^[[39m^M
Mongo Server and Mongosh versions:
root@d58a07d2fbe1:/# mongosh
Current Mongosh Log ID: 657bd6d21f9133d7393d36b5
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.2
Using MongoDB: 5.0.22
Using Mongosh: 2.0.2
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
Javascript file: testmongosh.js (to show the issue)
var mongo = db.getMongo()
bl_db = mongo.getDB("test-service")
bl_db.devops.PostProcessReconcile.deleteMany({"Details.PostprocessType":"Init"})
printjson(bl_db.devops.PostProcessReconcile.find({"Details.PostprocessType":"Init"}).count())
Adding this: I tried mongosh from within the container with --quiet flag and it seems to be doing the right thing. I am not sure where the issue is. (probably a term issue). Not sure why it does not exist with mongo but with mongosh.
docker exec -it d58a07d2fbe1 bash -c 'mongosh --quiet --file testmongosh.js | cat -v'
seems to return it correctly. Keeping this open, because I would like to get mongo’s view point.