Mongoose error: getaddrinfo ENOTFOUND localhost localhost:27017

Time:2019-10-23
{ Error: getaddrinfo ENOTFOUND localhost localhost:27017
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'localhost',
  host: 'localhost',
  port: 27017 }
mongoose.connect('mongodb://localhost:27017/db1',{
    poolSize:5,
    useNewUrlParser: true
},err=>{
    if(err){
        console.error(err)
    }else {
        Console.log ('mongodb successfully connected ')
    }
})

Try changing localhost to 127.0.0.1

mongoose.connect('mongodb://127.0.0.1:27017/db1',{
    poolSize:5,
    useNewUrlParser: true
},err=>{
    if(err){
        console.error(err)
    }else {
        Console.log ('mongodb successfully connected ')
    }
})

Recommended Today

Database lock (notes)

Introduction MyISAMTransaction is not supported. What is the difference between MyISAM and InnoDB in terms of locks MyISAMTable level lock is used by default, row level lock is not supported. InnoDBRow level locks are used by default, and table level locks are also supported. Read lock / shared lock: othersessionCan read, but can’t write. Write […]