Unable to Install Cockpit Using MongoDB - ConnectionTimeoutException

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:

**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->selectServer(Object(MongoDB\Driver\ReadPreference)) #1 /var/www/html/lib/MongoHybrid/Mongo.php(100): MongoDB\Collection->insertOne(Array) #2 /var/www/html/lib/MongoHybrid/Client.php(40): MongoHybrid\Mongo->insert('cockpit/account...', Array) #3 /var/www/html/install/index.php(63): MongoHybrid\Client->insert('cockpit/account...', Array) #4 {main} thrown in  **/var/www/html/lib/vendor/mongodb/mongodb/src/Collection.php**  on line  **797**

From localhost:8080:

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:

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

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

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 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:

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.

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'

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 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.

This post 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