Мангуста - не связываться с `mlab`, как это исправить? - PullRequest
0 голосов
/ 09 октября 2018

Вот мой код для соединения с mlab.но не может подключиться вообще.получая ошибку:

const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
const {connection, Schema} = mongoose;
const databaseURL = 'mongodb://3gwebtrain:Chennaixxx@ds125683.mlab.com:25683/users';

var db = mongoose.createConnection(databaseURL);

db.on('error', console.error.bind(console, 'connection error:'));


const UserSchema = new Schema({
    firstName:String,
    lastName:String,
    likes:[String]
});

const User = mongoose.model('User', UserSchema);

const addUser = (firstName,lastName) => new User({
    firstName,
    lastName
}).save();

const getUser = (id) => User.findById(id);

const removeUser = (id) => User.remove(id);

db.once('open', async() => {
    try{
        const newUser = await addUser('John', 'Smith')
    } catch(error){
        console.log(error);
    } finally{
        await connection.close();
    }
})

ошибка:

connection error: { MongoNetworkError: failed to connect to server [ds125683.mlab.com:25683] on first connect [MongoNetworkError: connect ECONNREFUSED 54.194.35.191:25683]
    at Pool.<anonymous> (D:\react\MERN\mern-cookbook\node_modules\mongodb-core\lib\topologies\server.js:503:11)
    at Pool.emit (events.js:182:13)
    at Connection.<anonymous> (D:\react\MERN\mern-cookbook\node_modules\mongodb-core\lib\connection\pool.js:326:12)
    at Object.onceWrapper (events.js:273:13)
    at Connection.emit (events.js:182:13)
    at Socket.<anonymous> (D:\react\MERN\mern-cookbook\node_modules\mongodb-core\lib\connection\connection.js:245:50)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  name: 'MongoNetworkError',
  message:
   'failed to connect to server [ds125683.mlab.com:25683] on first connect [MongoNetworkError: connect ECONNREFUSED 54.194.35.191:25683]' }

как это исправить?

...