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

Query SAP multiple database table sizes

Query SAP multiple database table sizes https://www.cnblogs.com/ken-yu/p/12973009.html Item code db02 Here are two approaches, In the first graphical interface, the results of the query data table are displayed in MB, and only one table can be queried at a time. SPACE—Segments—Detailed Analysis—Detailed Analysis  In the pop-up window segment / object, enter the name of the […]