Node.js Can';t使用mongoose连接mongoDB Atlas

Node.js Can';t使用mongoose连接mongoDB Atlas,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我正在做一个关于Nodejs的教程,它使用mongoose连接到mongodbatlas。问题是没有连接到MongoDB { MongoTimeoutError: Server selection timed out after 30000 ms at Timeout.setTimeout [as _onTimeout] (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/sdam/server_selecti

我正在做一个关于Nodejs的教程,它使用mongoose连接到mongodbatlas。问题是没有连接到MongoDB

{ MongoTimeoutError: Server selection timed out after 30000 ms
    at Timeout.setTimeout [as _onTimeout] (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/sdam/server_selection.js:308:9)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
  name: 'MongoTimeoutError',
  reason:
   { MongoError: bad auth Authentication failed.
       at _authenticateSingleConnection (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/auth/auth_provider.js:46:25)
       at sendAuthCommand (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/auth/scram.js:215:18)
       at _callback (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/connection/connect.js:320:5)
       at Connection.messageHandler (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/connection/connect.js:349:5)
       at Connection.emit (events.js:189:13)
       at processMessage (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/connection/connection.js:368:10)
       at TLSSocket.<anonymous> (/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/connection/connection.js:537:15)
       at TLSSocket.emit (events.js:189:13)
       at addChunk (_stream_readable.js:284:12)
       at readableAddChunk (_stream_readable.js:265:11)
       at TLSSocket.Readable.push (_stream_readable.js:220:10)
       at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
     name: 'MongoNetworkError',
     [Symbol(mongoErrorContextSymbol)]: {} },
  [Symbol(mongoErrorContextSymbol)]: {} }
{MongoTimeoutError:服务器选择在30000毫秒后超时
at Timeout.setTimeout[as _onTimeout](/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/sdam/server_selection.js:308:9)
在ontimeout(timers.js:436:11)
在tryOnTimeout(timers.js:300:5)
在listOnTimeout(timers.js:263:5)
at Timer.processTimers(timers.js:223:10)
名称:“MongoTimeoutError”,
原因:
{MongoError:错误的身份验证失败。
at_authenticateSingleConnection(/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/auth/auth_provider.js:46:25)
在sendAuthCommand(/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/auth/scram.js:215:18)
在回调时(/Users/rodrigo/Desktop/node\u login/node\u modules/mongodb/lib/core/connection/connect.js:320:5)
在Connection.messageHandler(/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/Connection/connect.js:349:5)
在Connection.emit(events.js:189:13)
在processMessage(/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/connection/connection.js:368:10)
在TLSSocket。(/Users/rodrigo/Desktop/node_login/node_modules/mongodb/lib/core/connection/connection.js:537:15)
在TLSSocket.emit(events.js:189:13)
在addChunk(_stream_readable.js:284:12)
在readableAddChunk(_stream_readable.js:265:11)
在TLSSocket.Readable.push(_stream_Readable.js:220:10)
在TLSWrap.onStreamRead[as onread](内部/stream_base_commons.js:94:17)
名称:“MongoNetworkError”,
[符号(mongoErrorContextSymbol)]:{},
[符号(mongoErrorContextSymbol)]:{}
以下是建立连接的方式:

const express = require('express');
const expressLayouts = require('express-ejs-layouts');
const mongoose = require('mongoose');


const app = express();

// DB Config
// url : mongodb+srv://rodrigo:<rodrigo>@recifeprev-xv52e.mongodb.net/test?retryWrites=true&w=majority
const db = require('./config/keys').MongoURI;

//Connect to mongo
mongoose.connect(db, {useNewUrlParser: true, useUnifiedTopology:true})
    .then(() => console.log('MongoDB Connected...'))
    .catch(err => console.log(err));



// EJS
app.use(expressLayouts);
app.set('view engine', 'ejs');

// Routes
app.use('/' , require('./routes/index'));
app.use('/users' , require('./routes/users'));

const PORT = process.env.PORT || 27017;


app.listen(PORT, console.log(`Server started on port ${PORT}`));
const express=require('express');
const expressLayouts=require('express-ejs-layouts');
const mongoose=require('mongoose');
常量app=express();
//数据库配置
//网址:mongodb+srv://rodrigo:@recifeprov-xv52e.mongodb.net/test?retryWrites=true&w=多数
const db=require('./config/keys')。MongoURI;
//连接到mongo
connect(db,{useNewUrlParser:true,useUnifiedTopology:true})
.then(()=>console.log('MongoDB Connected…'))
.catch(err=>console.log(err));
//EJS
应用程序使用(expressLayouts);
应用程序集(“查看引擎”、“ejs”);
//路线
应用程序使用(“/”,要求(“./路线/索引”);
应用程序使用('/users',require('/routes/users');
const PORT=process.env.PORT | | 27017;
app.listen(PORT,console.log(`Server start on PORT${PORT}`));
我正在使用我的机器ip,并检查了mogoDB上的ip白名单。

问题是“