Help connecting NodeJS to MongoDB

Today, I wanted to update an infrequently updated NodeJS + MongoDB application. It runs tests against MongoDB. However, when re-running the build today, without any changes, my code is unable to connect to the database.

To test, I’ve created mongo-experiments branch that tries to connect and change the database in a before_script. You can see here the error that is produced:

{ MongoError: failed to connect to server [] on first connect [MongoError: connect ECONNREFUSED]
    at Pool.<anonymous> (/home/travis/build/donejs/bitcentive/node_modules/mongodb-core/lib/topologies/server.js:336:35)
    at emitOne (events.js:96:13)
    at Pool.emit (events.js:188:7)
    at Connection.<anonymous> (/home/travis/build/donejs/bitcentive/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at Connection.g (events.js:292:16)
    at emitTwo (events.js:106:13)
    at Connection.emit (events.js:191:7)
    at Socket.<anonymous> (/home/travis/build/donejs/bitcentive/node_modules/mongodb-core/lib/connection/connection.js:189:49)
    at Socket.g (events.js:292:16)
    at emitOne (events.js:96:13)
  name: 'MongoError',
  message: 'failed to connect to server [] on first connect [MongoError: connect ECONNREFUSED]' }

Here is the .travis.yml file. I have the following (which, to the best of my understanding, should start mongo).

  - mongodb

Here is the script I am running is here. All it is trying to do is connect to the mongo instance:

MongoClient.connect("mongodb://", function (err, db) {

This works locally.

Any help would be greatly appreciated. Thanks!

You have a second services that hides your mongodb.

You need to combine them.

1 Like

I figured out my problem. When I said I didn’t make any changes, that wasn’t accurate. I had to make other changes to migrate to xenial. When I did, I created two services: configurations. One for mongodb another for xcfb.

I combined them and my build started passing. Thanks!