Lumber update - getaddrinfo ENOTFOUND mongodb-01

Hi team :wave:

I’m trying to update my models according the production environment.
In the machine I installed forest, I use the command
lumber update -c ./config/databases.js in the root folder (where there is my .env file),
and it returns me the error :

✖ Connecting to your database(s)
> Cannot connect to the database due to the following error:
> MongoServerSelectionError: getaddrinfo ENOTFOUND mongodb-01 mongodb-01:27017

However, when I can still access to my production data on forestapp.
So I guess the forest docker is able to login to my production DB and not lumber.

Here my .env

FOREST_ENV_SECRET=XYZ
FOREST_AUTH_SECRET=XYZ
DATABASE_URL=mongodb://{{user}}:{{pwd}}@51.280.110.0:27017/twake_console_accounts?authSource=admin
NODE_ENV=production
APPLICATION_URL=https://forest.twake.app
APPLICATION_PORT=5000

CORS_ORIGINS=

DATABASE_SSL=false
# This should be removed in production environment.
#DATABASE_REJECT_UNAUTHORIZED=false

Context

Please provide any relevant information about your setup.

  • Package Version: lumber 4.1.10
  • Express Version: “~4.17.1”
  • Database Dialect: mongodb
  • Database Version:
  • Project Name: Twake COnsole

Hello @Benoit-ln :wave:, and welcome to the Forest Admin community :tada:

Would that be possible for you to show me what is inside the ./config/databases.js file?
It looks like your database on mongodb-01:27017 is unreachable.

You can debug yourself by directly trying to connect to your mongo db database url this way:

const mongodb = require('mongodb');

mongodb.MongoClient.connect(connectionUrl, connectionOptionsMongoClient)
      .then((client) => client.db(options.dbName))
      .catch((error) => this.handleAuthenticationError(error));

You can read the documentation of the connect method of MongoClient here.

Thank you for the welcome :hugs:

Here my /config/database.js

const path = require('path');

const databaseOptions = {
  useNewUrlParser: true,
  useUnifiedTopology: true,
};

module.exports = [{
  name: 'default',
  modelsDir: path.resolve(__dirname, '../models'),
  connection: {
    url: process.env.DATABASE_URL,
    options: { ...databaseOptions },
  },
}];

I tested to connect manually, it worked with this code :

const mongodb = require('mongodb');

const connectionUrl = "mongodb://user:pwd@51.280.110.0:27017/twake_console_accounts?authSource=admin";

const connectionOptionsMongoClient = {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  serverSelectionTimeoutMS: 5000,
  family:4
};

const options = {
dbName : "twake_console_accounts"
}
mongodb.MongoClient.connect(connectionUrl, connectionOptionsMongoClient)
      .then((client) => {
   const db = client.db(options.dbName);
const collection = db.collection('users');
   collection.find({}).toArray(function(err, docs) {
    console.log('Found the following records');
    console.log(docs);
        });
}).catch((error) => console.log(error));

It’s why I don’t understand. When forest has to request my db, it is working, but not lumber-cli :thinking:

Quick question, does your host is equal to 51.280.110.0 or mongodb-01?

From what I understand, it should be 51.280.110.0.
Can you try by modifying your code with:

const connectionUrl = process.env.DATABASE_URL;

I don’t get why the error trace deals with mongodb-01 host…

Yes, my db is hosted on 51.280.110.0.

I updated the code to use the env file and it worked well :confused:

mongodb = require('mongodb');

const databaseOptions = {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  serverSelectionTimeoutMS: 5000,
  family:4
};

console.log(process.env.DATABASE_URL);
mongodb.MongoClient.connect(process.env.DATABASE_URL, databaseOptions)
      .then((client) => {
   const db = client.db();
const collection = db.collection('users');
   collection.find({}).toArray(function(err, docs) {
    console.log('Found the following records');
    console.log(docs);
        });
}).catch((error) => console.log(error));

The lumber code is open source and you can check your code against the reference here

Do you see any differences between your test and the lumber code?

Let me know :wink: