无法将 MongoDB Atlas 连接到我的 goorm IDE

Could not connect MongoDB Atlas to my goorm IDE

我是初学者

我目前正在设置我的 goorm IDE 并尝试连接 MongoDB Atlas。

但是,我无法将我的 MongoDB Atlas 集群连接到我的 goorm IDE,它显示了以下消息:

首次连接时出现错误,无法连接到服务器 [cluster0-shard-00-00-1kwgi.mongodb.net:27017] [MongoError: bad auth 身份验证失败。]

我按照 Ian Schoonover 的教程尝试将 IP 列入白名单 0.0.0.0/0。但是,我仍然无法连接我的 MongoDB Atlas。

下面是我在 IDE

中的代码
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');

mongoose.connect('mongodb+srv://dylanOh:123456@cluster0-1kwgi.mongodb.net/test?retryWrites=true&w=majority',{
    useNewUrlParser : true,
    useCreateIndex : true
}).then(()=>{
    console.log('Connected to DB!');
}).catch(err=>{
    console.log('ERROR',err.message);
});


app.use(bodyParser.urlencoded({extended: true}));

app.set('view engine', 'ejs');



//Below is my testing info before setting up the database

const campgrounds =[
{name: 'Shenandoah', image:'https://www.nps.gov/shen/planyourvisit/images/20170712_A7A9022_nl_Campsites_BMCG_960.jpg?maxwidth=1200&maxheight=1200&autorotate=false'},
{name: 'Mount Rainier', image:'https://www.nps.gov/mora/planyourvisit/images/OhanaCampground2016_CMeleedy_01_web.jpeg?maxwidth=1200&maxheight=1200&autorotate=false'},
{name: 'Florida', image:'https://www.visitflorida.com/content/visitflorida/en-us/places-to-stay/campgrounds-florida/_jcr_content/full_width/vf_image.img.1280.500.jpg'}]


app.get('/',(req, res)=>{
    res.render('landing');
});



app.get('/campgrounds', (req,res)=>{

    res.render('campgrounds', {campgrounds:campgrounds});
});

app.post('/campgrounds', (req,res)=>{
    const name=req.body.name ;
    const image=req.body.image;
    const newCampground = {name:name, image:image}
    campgrounds.push(newCampground);
    res.redirect('/campgrounds');
});


app.get('/campgrounds/new', (req,res)=>{
    res.render('new');
});



app.listen('3000', ()=>{
    console.log('YelpCamp has started!');
});

作为预期结果,它应该在我的终端显示 'Connected to DB!'。

但是,显示了 'ERROR failed to connect to server [cluster0-shard-00-00-1kwgi.mongodb.net:27017] on first connect [MongoError: bad auth Authentication failed.]'。

我建议你创建一个新的数据库用户,因为错误是一个身份验证错误,你可能会忘记你第一个创建的数据库用户的密码,我有时在第一次创建用户时忘记它:)

你看到“测试”了吗?在 url 中?必须将其替换为您尝试连接的集合的名称。