Saturday, 27 May 2017

MongoDb Atlas failed to connect to server [123:27017] on first connect

I'm trying to connect to a MongoDB in MongoDB Atlas, but I'm receing this error:

{ MongoError: failed to connect to server [123:27017] on first connect [MongoError: connect EHOSTUNREACH 0.0.0.123:27017 - Local (192.168.15.6:56553)]
    at Pool.<anonymous> (/Users/filipeferminiano/node_modules/mongodb-core/lib/topologies/server.js:328:35)
    at emitOne (events.js:96:13)
    at Pool.emit (events.js:191:7)
    at Connection.<anonymous> (/Users/filipeferminiano/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at Object.onceWrapper (events.js:293:19)
    at emitTwo (events.js:106:13)
    at Connection.emit (events.js:194:7)
    at TLSSocket.<anonymous> (/Users/filipeferminiano/node_modules/mongodb-core/lib/connection/connection.js:177:49)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:96:13)
  name: 'MongoError',

This is my code:

var db;
var mongoServer = 'mongodb://[USER]:[PASSWORD]@roas-shard-00-00-r4v7u.mongodb.net:27017,roas-shard-00-01-r4v7u.mongodb.net:27017,roas-shard-00-02-r4v7u.mongodb.net:27017/[DATABASE]?ssl=true&replicaSet=roas-shard-0&authSource=admin'.replace(/\\/g, "\\\\");

MongoClient.connect(mongoServer, (err, database) => {
   if (err) return console.log(err)
      db = database
      app.listen(3000, () => {
        console.log('listening on 3000')
  })
})



via Filipe Ferminiano

No comments:

Post a Comment