root@goorm:/workspace# mongo
MongoDB shell version v4.0.22
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-03-08T17:13:30.902+0000 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketExcepti
on: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:356:17
@(connect):2:6
exception: connect failed
Okay, it was my fault
Here is how I fix. First
Open terminal and use this command(Remember about Note) , mongod --dbpath data Second
Run the app.js file from project’s directory
For me it was, node app.js
Finally,
Use mongo command from the up above directory of data, mongo
Note:
There should have a directory named data from where you are calling mongo. In my case, data is a directory inside workspace. So, in workspace, I used mongo command.