首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将MongoDB地图集连接到我的goorm IDE

无法将MongoDB地图集连接到我的goorm IDE
EN

Stack Overflow用户
提问于 2019-08-19 21:52:32
回答 2查看 942关注 0票数 0

我是这里的初学者。

我目前正在设置我的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中的代码

代码语言:javascript
复制
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错误身份验证失败。‘被展示出来。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-20 16:19:59

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

票数 0
EN

Stack Overflow用户

发布于 2019-10-07 17:16:20

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57558179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档