'Mongo shutting down with error code(1) after running the mongo command

I am new to MongoDB and I keep getting a SocketException and a shutting down with exit code : 1 error. I have also tried stopping and restarting the mongod servers. The error I get is as follows :

root@sam-sepiol:~# mongo
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-07-01T08:19:45.406-0400 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-07-01T08:19:45.407-0400 F  -        [main] exception: connect failed
2020-07-01T08:19:45.407-0400 E  -        [main] exiting with code 1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source