数据库代码:
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient;
const mongoConnect = callback => {
MongoClient.connect('mongodb+srv://shubhamt10:shubham123@cluster0-g2s9w.mongodb.net/test?retryWrites=true',
{ useNewUrlParser: true})
.then(client => {
console.log('Connected!');
callback(client);
})
.catch(err => {
console.log(err);
});
}
module.exports = mongoConnect;
app.js代码
const mongoConnect = require('./util/database');
mongoConnect(client => {
console.log(client);
app.listen(3000);
});
我收到此错误: {MongoNetworkError:与cluster0-shard-00-02-g2s9w.mongodb.net:27017的连接5已关闭 在TLSSocket。 (E:\ Node JS \ Final Project \ node_modules \ mongodb-core \ lib \ connection \ connection.js:276:9) 在Object.onceWrapper(events.js:285:13) 在TLSSocket.emit(events.js:202:15) 在_handle.close(net.js:611:12) 在TCP.done(_tls_wrap.js:390:7) 名称:“ MongoNetworkError”, errorLabels:['TransientTransactionError'], [Symbol(mongoErrorContextSymbol)]:{}}