# Unable to Install Cockpit Using MongoDB - ConnectionTimeoutException

**URL:** <https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239>\
**Category:** Support\
**Created:** [September 3, 2018, 7:18am UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239 "2018-09-03T07:18:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-born](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@alex-born](https://discourse.getcockpit.com/u/alex-born)\
**Post date:** [September 3, 2018, 7:18am UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239/1 "2018-09-03T07:18:02Z")

</div>

Loving the tool so far!

I’m trying to install cockpit with the mongodb database but I am running into some issues. When I enter the database information into the config file, entire CMS fails and throws the following error:

From `localhost:8080/install`:

```auto
**Fatal error** : Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No servers yet eligible for rescan in /var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php:797 Stack trace: #0 /var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php(797): MongoDB\Driver\Manager-&gt;selectServer(Object(MongoDB\Driver\ReadPreference)) #1 /var/www/html/lib/MongoHybrid/Mongo.php(100): MongoDB\Collection-&gt;insertOne(Array) #2 /var/www/html/lib/MongoHybrid/Client.php(40): MongoHybrid\Mongo-&gt;insert('cockpit/account...', Array) #3 /var/www/html/install/index.php(63): MongoHybrid\Client-&gt;insert('cockpit/account...', Array) #4 {main} thrown in **/var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php** on line **797**

```

From `localhost:8080`:

```auto
Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionTimeoutException: No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on 'localhost:27017'] in /var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php:519 Stack trace: #0 /var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php(519): MongoDB\Driver\Manager->selectServer(Object(MongoDB\Driver\ReadPreference)) #1 /var/www/html/lib/MongoHybrid/Mongo.php(66): MongoDB\Collection->find(Array, Array) #2 [internal function]: MongoHybrid\Mongo->find('cockpit/webhook...') #3 /var/www/html/lib/MongoHybrid/Client.php(420): call_user_func_array(Array, Array) #4 /var/www/html/modules/Cockpit/webhooks.php(8): MongoHybrid\Client->__call('find', Array) #5 /var/www/html/modules/Cockpit/bootstrap.php(336): include_once('/var/www/html/m...') #6 /var/www/html/lib/Lime/App.php(1340): require('/var/www/html/m...') #7 /var/www/html/lib/Lime/App.php(1299): Lime\App->bootModule(Object(Lime\Module)) #8 /var/www/html/lib/Lime/App.php(1323): Lim in /var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php on line 519

```

Content of `config.yaml`:

```auto
database:
    server: mongodb://localhost:27017
    options:
        db: cockpitdb

```

I have verified that the mongodb is running using RoboMongo. I can connect to the database and edit data. How can I fix this issue?

Other info:

System: OSX Sierra 10.12.6  
Mongo Version: v4.0.1  
Docker Version: 18.06.1-ce, build e68fc7a

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [September 3, 2018, 10:21am UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239/2 "2018-09-03T10:21:14Z")

</div>

Hi @alex-born, not sure if it’s the issue but I also have to define the username and password like below example:

```
database:
   server: mongodb://mongo-host:27017
   options:
       db: cockpitdb
       username: root
       password: root 

```

on your mongoserver make sure that you db exists and has grant permissions for defined username

---

<div class="post-metadata">

**Author:** ![alex-born](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@alex-born](https://discourse.getcockpit.com/u/alex-born)\
**Post date:** [September 3, 2018, 7:55pm UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239/3 "2018-09-03T19:55:13Z")

</div>

Hello @pauloamgomes. If I remember correctly, mongodb creates a database on first use. Just in case, I created a `cockpitdb` database and artificially preserved it by inserting a record. Now I when I list the databases, it shows up. I never enabled authentication (by running with `--auth`). Thus, I could attach using the terminal client just by specifying the port. I wanted to try running with auth. I enabled authentication following [this](https://stackoverflow.com/questions/38921414/mongodb-what-are-the-default-user-and-password) stack overflow post.

I created an admin user like this: `db.createUser({user:"root",pwd:"root",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})`  
Now, I can attach via terminal like this: `mongo --port 27017 -u "root" -p "root" --authenticationDatabase "admin"`

So, I tried modifying the config file accordingly:

```auto
database:
   server: mongodb://localhost:27017
   options:
       db: cockpitdb
       username: root
       password: root 

```

I assume that the db option is the database that cockpit will utilize to store data. Regardless, I tried to the authentication database. Cockpit failed both times throwing the same error as before.

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [September 3, 2018, 10:44pm UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239/4 "2018-09-03T22:44:30Z")

</div>

Hi @alex-born,

not sure if you did all the steps properly, mine are:

```
$ mongo

> use admin
> db.createUser({user:"root",pwd:"root", roles:[{role:"root",db:"admin"}]})
> exit

$ mongo --port 27017 -u root -p root --authenticationDatabase admin

> use cockpitdb
> db.createUser({user:"root",pwd:"root", roles:["readWrite"]})

```

in such case you can also give a try on using docker, seems to work well to me, example docker-compose.yml:

```
version: "2"

services:

  cockpit-cms-mongo:
    image: mongo
    environment:
        MONGO_INITDB_DATABASE: "cockpitdb"
        MONGO_INITDB_ROOT_USERNAME: root
        MONGO_INITDB_ROOT_PASSWORD: root
    ports:
    - "27017:27017"

  cockpit-cms-php:
    image: wodby/php:7.1
    environment:
      PHP_FPM_CLEAR_ENV: "no"
    volumes:
      - ./www:/var/www/html

  cockpit-cms-nginx:
    image: wodby/php-nginx:1.13
    depends_on:
      - cockpit-cms-php
    environment:
      NGINX_STATIC_CONTENT_OPEN_FILE_CACHE: "off"
      NGINX_ERROR_LOG_LEVEL: error
      NGINX_BACKEND_HOST: cockpit-cms-php
      NGINX_SERVER_ROOT: /var/www/html
    volumes:
      - ./www:/var/www/html
    ports:
      - '8000:80'
```

---

<div class="post-metadata">

**Author:** ![alex-born](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@alex-born](https://discourse.getcockpit.com/u/alex-born)\
**Post date:** [September 4, 2018, 2:24am UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239/5 "2018-09-04T02:24:31Z")

</div>

I took all the same steps you did to setup the database and privileges. I also can’t get webhooks using an express server over localhost. Maybe it’s a connected issue and they just can’t talk. I posted a [stack overflow question](https://stackoverflow.com/questions/52156422/receiving-webhook-in-express-from-local-application) thinking that was a problem with my code / headers. Node, Mongo and Cockpit are running locally on my machine.

I’m trying the docker method now.

---

<div class="post-metadata">

**Author:** ![hellmaca](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/hellmaca/32/126_2.png) [@hellmaca](https://discourse.getcockpit.com/u/hellmaca)\
**Post date:** [October 23, 2018, 6:20pm UTC](https://discourse.getcockpit.com/t/unable-to-install-cockpit-using-mongodb-connectiontimeoutexception/239/6 "2018-10-23T18:20:37Z")

</div>

This [post](https://github.com/agentejo/cockpit/issues/602) helped me connect to mongodb. The config.yaml file content is a little different

```
    database:    
        server: mongodb://username:password@ipaddress:27017/dbname
        options:
            db: dbname
```
