发生Mongoose connectio MongoNetworkError:与cluster0-shard-00-01-utzss.mongodb.net的连接0:27017关闭错误

时间:2019-09-14 09:42:26

标签: javascript node.js mongodb mongoose

Mongoose default connection is disconnected
Mongoose default connection has occured MongoNetworkError: connection 0 to cluster0-shard-00-01-utzss.mongodb.net:27017 closed error
(node:8421) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 0 to cluster0-shard-00-01-utzss.mongodb.net:27017 closed
    at TLSSocket.<anonymous> (/media/tyro/6250439650437039/Work Space/Web/JS-Learning/node-restfulApi-shop/node_modules/mongodb/lib/core/conn
ection/connection.js:352:9)

 const dbURL  = 'mongodb+srv://node-rest-shop:node-rest-shop@cluster0-utzss.mongodb.net/test?retryWrites=true&w=majority';
 mongoose.connect(dbURL,{ useUnifiedTopology: true, useNewUrlParser: true });
 mongoose.connection.on('connected', function(){
    console.log("Mongoose default connection is open to ", dbURL);
  });
 mongoose.connection.on('error', function(err){
     console.log("Mongoose default connection has occured "+err+" error");
 });
 mongoose.connection.on('disconnected', function(){
     console.log("Mongoose default connection is disconnected");
 });

0 个答案:

没有答案