Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
(node:16686) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017

While conencting mongoDb with application facing issue : "UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017"

Tried Solutions :

  1. Reinstalling mongoDb
  2. Restarting the mongoDb service from control panel services.
  3. Reinstalling the mongoose.

Code :

var express = require('express');
var app = new express();
var bodyParser = require('body-parser')
var mongoose = require('mongoose')
var user = require('./model/user')
const hostname = '127.0.0.1';
const port = 3000;
var router = express.Router();
mongoose.connect('mongodb://localhost:27017/userdb', { useNewUrlParser: true });
var users = [{ name: "Jane", age: 20 }, { name: "Mark", age: 40 }, { name: "Janefer", age: 40 }]
app.use(bodyParser.urlencoded({ extended: true }))//converts it into obj

router.route('/users')
    .get((req, res) => {
        //fetch record from users collectiobn
        user.find({}, (err, users) => {
            if (err) {
                res.json({ msg: 'error in fetching data from DB' })
            }
            else {
                res.json(users)
            }
        })
        // res.json(users)
    })
    .post((req, res) => {

    })
app.use('/api', router)//middleware to direct all req 
app.listen(port, hostname, () => {
    console.log("Server listening on 3000")
})

Error screenshot :

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can try to check which port mongodb is using in your mongodb.conf after that if you still are have problem you can run the command ps aux | grep mongo and post the result.

about 4 years ago · Juan Pablo Isaza Report

0

Instead of [localhost] use [127.0.0.1]. like this - 'mongodb://127.0.0.1:27017/userdb'

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!