MongoError: connection 0 to localhost:27017 timed out

前端 未结 4 1657
灰色年华
灰色年华 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
    });
    
    0 讨论(0)
  • 2020-12-19 01:53

    If you are sure that you exported port -p 27017:2017 and it still doesn't work.

    Check your VPN if it is not blocking Local Network sharing.

    0 讨论(0)
  • 2020-12-19 02:01

    Your query is taking a long time. And mongo itself has a default time out set. So it times out, if the query takes longer than the timeout time.

    0 讨论(0)
  • 2020-12-19 02:08

    you have to use this configs on your connection: keepAlive: 300000, connectTimeoutMS: 30000

    0 讨论(0)
提交回复
热议问题