无法连接到 mongodb-atlas 上的 mongodb

Couldn't connect to mongodb on mongodb-atlas

正在尝试连接到 mongodb-atlas 上的 mongodb 免费数据库 我几乎尝试了所有方法检查了文档,更改了 url,更改了密码,甚至删除了用户并创建了新用户,但仍然没有解决问题

这里是myurl.js文件

module.exports = {
    mongoURL: "mongodb+srv://nansDB:nansDB123@nodecluster-qs6cv.mongodb.net/test?retryWrites=true&w=majority",
    secret: "mystrongsecret"
}

这是我的 index.js 文件

const express = require('express');
const mongoose = require('mongoose');
const app = express();

//mongodb Configuration
const db = require('./setup/myurl').mongoURL;

//attempt to connect to database
mongoose.connect(db,  { useNewUrlParser: true })
        .then(()=> console.log('MongoDb Connect successfully'))
        .catch(err => console.log(err));

const port = process.env.PORT || 3000;

这是我每次尝试 运行

时遇到的错误行
{ MongoNetworkError: failed to connect to server [nodecluster-shard-00-02-qs6cv.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to nodecluster-shard-00-02-qs6cv.mongodb.net:27017 closed]
    at Pool.<anonymous> (D:\nodejsProject\bigStack\node_modules\mongodb-core\lib\topologies\server.js:431:11)
    at Pool.emit (events.js:189:13)
    at connect (D:\nodejsProject\bigStack\node_modules\mongodb-core\lib\connection\pool.js:557:14)
    at callback (D:\nodejsProject\bigStack\node_modules\mongodb-core\lib\connection\connect.js:109:5)
    at runCommand (D:\nodejsProject\bigStack\node_modules\mongodb-core\lib\connection\connect.js:129:7)
    at Connection.errorHandler (D:\nodejsProject\bigStack\node_modules\mongodb-core\lib\connection\connect.js:321:5)
    at Object.onceWrapper (events.js:277:13)
    at Connection.emit (events.js:189:13)
    at TLSSocket.<anonymous> (D:\nodejsProject\bigStack\node_modules\mongodb-core\lib\connection\connection.js:350:12)
    at Object.onceWrapper (events.js:277:13)
    at TLSSocket.emit (events.js:189:13)
    at _handle.close (net.js:597:12)
    at TCP.done (_tls_wrap.js:388:7)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

它解决了实际上我的白名单 ip 因为连接问题 [重新连接到 wifi] 而被更改。虽然我的建议是检查你白名单的ip是否存在