I have an app developed using MEAN stack. I am getting the following error
(node:4920) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: failed to connect to server [ds047865.mongolab.com:47865] on first connect [Mon goError: connect ECONNREFUSED 130.211.211.211:47865]
(node:4920) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
here is my code:
var mongoose = require('mongoose');
var validator = require('mongoose-unique-validator');
var nodemailer = require('nodemailer');
mongoose.connect('mongodb://naresh:[email protected]:49025/languageapp', { useMongoClient: true });
var db = mongoose.connection;
db.on('connect', function () { console.log('connected'); });
var userSchema = new mongoose.Schema({
userName: { type: String, required: true, index: true, unique: true },
userEmail: { type: String, required: true, index: true, unique: true },
userPass: { type: String, required: true },
Date: { type: String, default: Date.now() },
userResult: String
});
var questionSchema = new mongoose.Schema({
question: { type: String, unique: true },
op1: String,
op2: String,
op3: String,
op4: String,
rightAnswer: String,
questionType: String,
questionID: String,
quizTopic: String,
CreatedAt: { type: String, default: Date.now() }
});
var resultSchema = new mongoose.Schema({
userID: String,
userName: String,
userMatriculation: String,
userEmail: String,
quizTopic: String,
userResult: String,
date: { type: String, default: Date.now() }
});
userSchema.plugin(validator);
var User = mongoose.model('Users', userSchema);
var Question = mongoose.model('Questions', questionSchema);
var Result = mongoose.model('Results', resultSchema);
I am not using any promises though am getting these errors.
connect
method to handle the error message. See here. Finally, I think the connected event is calledconnected
, notconnect
. - Mika SundlandECONNREFUSED
is the important part. You can Google it and try to look at other people's solution to the problem. I doubt it can be solved by code.UnhandledPromiseRejectionWarning
is not the essential part. It just means you are not handling the promise thatconnect
returns. It will most likely go away if you chain acatch()
to it. - Mika Sundland