2

I just got started using strapi framework and I would like to use mLab as my mongoDB database, so I go to configure strapi and fill the following details:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-mongoose",
      "settings": {
        "client": "mongo",
        "host": "localhost",
        "port": 27017,
        "database": "development",
        "username": "",
        "password": ""
      },
      "options": {}
    }
  }
}

The details I get from mLab are:

mongodb://myUsername:myPassword@ds047891.mlab.com:41365/myDatabase

Here is my final config:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-mongoose",
      "settings": {
        "client": "mongo",
        "host": "ds047891.mlab.com",
        "port": 41365,
        "database": "myDatabase",
        "username": "myUsername",
        "password": "myPassword"
      },
      "options": {}
    }
  }
}

When I try to start strapi, I get the following error:

DEBUG (2748 on DESKTOP-HAL1ATE): Server wasn't able to start properly.
ERROR (2748 on DESKTOP-HAL1ATE): (hook:mongoose) takes too long to load

I think that I did not setup my configuration right, but I can't pinpoint where the problem is. I hope someone could, thanks.

1 Answers1

2

I am Pierre, on of the creators of Strapi. I tried with the following configuration and it worked well:

{ "defaultConnection": "default", "connections": { "default": { "connector": "strapi-mongoose", "settings": { "client": "mongo", "host": "ds135777.mlab.com", "port": "35777", "database": "myDatabase", "username": "myUsername", "password": "myPassword" }, "options": {} } } }

Our configurations files look quiet similar.

What file did you updated (/config/environment/development/database.json or /config/environment/production/database.json)?

Are you sure you entered the correct username and password? Did you try to login to your MongoDB instance through the command line mongo ds135777.mlab.com:35777/myDatabase -u <dbuser> -p <dbpassword>?

UPDATE

In version >= 3 for mlab don't forget to specify authenticationDatabase

"options": {
    "authenticationDatabase": "your_mlad_database_name",
    "ssl": false
  }
xargr
  • 2,788
  • 1
  • 19
  • 28
Pierre
  • 986
  • 8
  • 13
  • 1
    Yes it works now, I had a problem with the port but mLab support helped. Thanks for taking the time to help me Pierre, much appreciated. – Abderrahman Gourragui Jan 18 '18 at 10:49
  • Ok, great. Have fun using Strapi! – Pierre Jan 18 '18 at 11:16
  • could you explaing how did the port mlab support helped...as me too getting the same issue – Rohit Kumar Feb 11 '18 at 17:29
  • Please take a look at this tutorial: https://medium.com/@strapi/using-mlab-with-strapi-e3f968a9c530. – Pierre Feb 12 '18 at 18:17
  • The `Update` is what I was looking for. Please add it to your documentation as this wasted my entire day trying to figure out what's the issue. Also `mLab` was acquired by `Atlas`, so it would be nice to also include a way to connect to `Atlas` – STIKO Oct 17 '18 at 22:38