我是这里的初学者。
我目前正在设置我的goorm IDE,并尝试连接MongoDB地图集。
然而,我无法将我的MongoDB Atlas集群连接到我的goorm IDE,它显示了以下消息:
错误:无法连接到服务器cluster0-shard-00-00-1kwgi.mongodb.net:27017错误:第一次连接MongoError:身份验证失败。
按照Ian Schoonover的教程,我尝试使用0.0.0.0/0将IP列入白名单。但是,我仍然无法连接我的MongoDB地图集。
下面是我在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!”在我的终点站。
但是,无法连接到服务器cluster0-shard-00-00-1kwgi.mongodb.net:27017。第一次连接时出错。MongoError:a错误身份验证失败。‘被展示出来。
发布于 2019-08-20 16:19:59
我建议您创建一个新的db用户,因为这个错误是一个身份验证错误,您可能会忘记第一个创建的db用户的密码,有时我在第一次创建用户时会忘记密码:)
发布于 2019-10-07 17:16:20
你看到“测试?”在url中?它必须替换为您尝试连接到的集合的名称。
https://stackoverflow.com/questions/57558179
复制相似问题