MongoError: connection 0 to localhost:27017 timed out

前端 未结 4 1675
灰色年华
灰色年华 2020-12-19 01:08
events.js:141
      throw er; // Unhandled \'error\' event
MongoError: connection 0 to localhost:27017 timed out
at Function.MongoError.create (/home/ubuntu/scripts/         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 01:47

    const mongoose = require('mongoose');
    const option = {
        socketTimeoutMS: 30000,
        keepAlive: true,
        reconnectTries: 30000
    };
    
    const mongoURI = process.env.MONGODB_URI;
    mongoose.connect(mongoURI, option).then(function(){
        //connected successfully
    }, function(err) {
        //err handle
    });
    

提交回复
热议问题