Search code examples
mongodbinstallationfedora

Connection error while installing mongodb on Fedora 28


I have been trying to install Mongodb but it keeps failing midway. When the download is complete, installation fails with a connection error:

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-08-17T12:26:33.340+0200 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-08-17T12:26:33.340+0200 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

What I've tried:
1. Changing the port:
mongo --port 4332
but it doesn't connect still:

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:4332/
2018-08-17T12:32:55.743+0200 W NETWORK  [thread1] Failed to connect to 127.0.0.1:4332, in(checking socket for error after poll), reason: Connection refused
2018-08-17T12:32:55.743+0200 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:4332, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed
  1. Reinstalling the DB shows up as complete but I still can't start it. Check out the screenshot

An image showing an error while installing mongodb

  1. Checking for any config files in /etc/mongo* or /var/lib/: there is none.
    Note: There's no mongod service available too.

Solution

  • the installation seem to have worked, but the mongod was not started.

    MongoDB need two element :

    the "mongo" shell utility, who is used to connect to the database direcly the "mongod" service, who is the true database programs.

    to start the mongod, simply use a cmd and use the "mongod" command. this command may fail if :

    • the port is already used (default is 27017)
    • the dbpath directory was not created (default is /data/db)

    Fedora repository do not install both at the same time. the shell is in the repository under the "mongodb" name the server is under the name "mongodb-server"

    so to install both, you need to do

    dnf install mongodb mongodb-server
    

    and you can then start the mongod service with

    sudo service mongod start
    

    more information