Search code examples
mongodbmern

Running `mongo` in the command line is giving error


I am trying to start a MERN app, I have installed mongo and any relevant things. But when I run mongo in my terminal the following appears. I have looked across the board but the solutions do not help me. I am also running on Ubuntu 20.04.

MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
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:374:17
@(connect):2:6
exception: connect failed
exiting with code 1


Solution

  • Fixed the issue by running

    $ sudo rm -rf /tmp/mongodb-27017.sock
    
    $ sudo service mongod start