root@Wavynn-master:~# sudo service mongod start
root@Wavynn-master:~# mongo
MongoDB shell version v4.2.1
connecting to: mongodb://
2019-11-04T18:18:00.829+0000 E  QUERY    [js] Error: couldn't connect to server, connection attempt failed: SocketException: Error connecting to :: caused by :: Connection refused :
2019-11-04T18:18:00.830+0000 F  -        [main] exception: connect failed
2019-11-04T18:18:00.830+0000 E  -        [main] exiting with code 1

Hello. I have been attempting to pair my mongoDB with compass, compass asked for a authentication database, in which I used a tutorial, where I created a db called admin, and an admin role having all permissions to all databases.

This can be seen here

use admin;
switched to db admin
> db.createUser({
... user: "admin",
... pwd: "*********",
... roles: [
... {role: "userAdminAnyDatabase", db: "admin" },
... {role: "readWriteAnyDatabase", db: "admin" },
... {role: "dbAdminAnyDatabase", db: "admin" }
... ]
... });
Successfully added user: {
        "user" : "admin",
        "roles" : [
                        "role" : "userAdminAnyDatabase",
                        "db" : "admin"
                        "role" : "readWriteAnyDatabase",
                        "db" : "admin"
                        "role" : "dbAdminAnyDatabase",
                        "db" : "admin"

Right after this issue started occuring.

Anyone have any suggestions as to how we fix this issue? Also a tip towards how we connect compass with mongoDB on ubuntu :)

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

3 answers

I was facing the same issue in ArchLinux. I just restarted my mongodb service with sudo systemctl restart mongodb.service and worked for me.

hello i have the same problem i would like to know how are you fix it

Try to uninstall and remove all directories that are created by the first installation.
Don’t forget to run: sudo apt-get autoremove
Then install it from from the beginning, check official page of MongoDB for the steps.

Submit an Answer