Mongosh terminated immediately

OS: CentOS 7

When I try to start the Mongo Shell by using “mongosh”, it quits immediately.

root@localhost#mongosh
Current Mongosh Log ID:	622234fa2795d4ed10169c8b
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.2
Using MongoDB:		5.0.6
Using Mongosh:		1.2.2

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting:
   2022-03-04T21:25:53.332+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2022-03-04T21:25:53.332+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
   2022-03-04T21:25:53.332+08:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
------

test> 
<--- quit immediately back to the command shell
root@localhost#

I have checked the log located in the following folder : /root/.mongodb/mongosh


{"t":{"$date":"2022-03-04T15:49:14.920Z"},"s":"I","c":"MONGOSH","id":1000000000,"ctx":"log","msg":"Starting log","attr":{"execPath":"/usr/bin/mongosh","envInfo":{"EDITOR":null,"NODE_OPTIONS":null,"TERM":null},"version":"1.2.2","distributionKind":"compiled","buildArch":"x64","buildPlatform":"linux","buildTarget":"linux-x64","buildTime":"2022-02-24T16:23:54.809Z","gitVersion":"7956ae40dde9eb7e6ee8cad058f88953781dc049","nodeVersion":"v14.18.3"}}
{"t":{"$date":"2022-03-04T15:49:14.923Z"},"s":"I","c":"MONGOSH","id":1000000005,"ctx":"config","msg":"User updated"}
{"t":{"$date":"2022-03-04T15:49:14.923Z"},"s":"I","c":"MONGOSH","id":1000000048,"ctx":"config","msg":"Loading global configuration file","attr":{"filename":"/etc/mongosh.conf","found":false}}
{"t":{"$date":"2022-03-04T15:49:14.955Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000042,"ctx":"mongosh-connect","msg":"Initiating connection attempt","attr":{"uri":"mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.2","driver":{"name":"nodejs|mongosh","version":"4.4.0"},"devtoolsConnectVersion":"1.2.4","host":"127.0.0.1:27017"}}
{"t":{"$date":"2022-03-04T15:49:14.993Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000035,"ctx":"mongosh-connect","msg":"Server heartbeat succeeded","attr":{"connectionId":"127.0.0.1:27017"}}
{"t":{"$date":"2022-03-04T15:49:15.006Z"},"s":"I","c":"DEVTOOLS-CONNECT","id":1000000037,"ctx":"mongosh-connect","msg":"Connection attempt finished"}
{"t":{"$date":"2022-03-04T15:49:15.024Z"},"s":"I","c":"MONGOSH","id":1000000004,"ctx":"connect","msg":"Connecting to server","attr":{"session_id":"622234fa2795d4ed10169c8b","userId":"622209b8cf515782aa7cef00","connectionUri":"mongodb://<ip address>:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.2","is_atlas":false,"is_localhost":true,"is_do":false,"server_version":"5.0.6","node_version":"v14.18.3","mongosh_version":"1.2.2","server_os":"linux","server_arch":"x86_64","is_enterprise":false,"auth_type":null,"is_data_lake":false,"dl_version":null,"atlas_version":null,"is_genuine":true,"non_genuine_server_name":"mongodb","fcv":"5.0","api_version":null,"api_strict":null,"api_deprecation_errors":null}}
{"t":{"$date":"2022-03-04T15:49:15.027Z"},"s":"I","c":"MONGOSH","id":1000000011,"ctx":"shell-api","msg":"Performed API call","attr":{"method":"adminCommand","class":"Database","db":"test","arguments":{"cmd":{"getLog":"startupWarnings"}}}}
{"t":{"$date":"2022-03-04T15:49:15.027Z"},"s":"I","c":"MONGOSH","id":1000000011,"ctx":"shell-api","msg":"Performed API call","attr":{"method":"getSiblingDB","class":"Database","db":"test","arguments":{"db":"admin"}}}
{"t":{"$date":"2022-03-04T15:49:15.028Z"},"s":"I","c":"MONGOSH","id":1000000011,"ctx":"shell-api","msg":"Performed API call","attr":{"method":"adminCommand","class":"Database","db":"test","arguments":{"cmd":{"ping":1}}}}
{"t":{"$date":"2022-03-04T15:49:15.029Z"},"s":"I","c":"MONGOSH","id":1000000011,"ctx":"shell-api","msg":"Performed API call","attr":{"method":"getSiblingDB","class":"Database","db":"test","arguments":{"db":"admin"}}}
{"t":{"$date":"2022-03-04T15:49:15.061Z"},"s":"I","c":"MONGOSH","id":1000000010,"ctx":"shell-api","msg":"Initialized context","attr":{"method":"setCtx","arguments":{}}}
{"t":{"$date":"2022-03-04T15:49:15.062Z"},"s":"I","c":"MONGOSH-SNIPPETS","id":1000000024,"ctx":"snippets","msg":"Fetching snippet index","attr":{"refreshMode":"allow-cached"}}
{"t":{"$date":"2022-03-04T15:49:15.063Z"},"s":"I","c":"MONGOSH-SNIPPETS","id":1000000019,"ctx":"snippets","msg":"Loaded snippets","attr":{"installdir":"/root/.mongodb/mongosh/snippets"}}
{"t":{"$date":"2022-03-04T15:49:15.078Z"},"s":"I","c":"MONGOSH","id":1000000002,"ctx":"repl","msg":"Started REPL","attr":{"version":"1.2.2"}}
{"t":{"$date":"2022-03-04T15:49:15.792Z"},"s":"I","c":"MONGOSH","id":1000000045,"ctx":"analytics","msg":"Flushed outstanding data","attr":{"flushError":null,"flushDuration":706}}

Any idea why the mongosh terminated immediately?

Venom

Hello @K.H_Cheung – I am wondering why you are running mongosh as root?

Hi, I am running the CentOS 7 in a virtual box for testing only. I have tried to run the mongosh through the Linux Desktop terminal and confirmed the session would not be terminated immediately. If I run the mongosh through the Command Shell provided by Webmin, the session would be terminated immediately. I think the root cause might be related to the Webmin instead of MongoDB.

1 Like