在mongodb-atlas上无法连接到mongodb [英] Couldn't connect to mongodb on mongodb-atlas

查看:463
本文介绍了在mongodb-atlas上无法连接到mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to connect to the mongodb free database on mongodb-atlas I've almost tried everything Checked the docs, Changed the url, Changing password and even deleted the user and created the new one but still not resolve the problem

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是否存在.

Its solved actually my whitelisted ip was changed because of connection issue [reconnecting to wifi]. Although my suggestion is checked whether the ip you whitelisted is exists or not.

这篇关于在mongodb-atlas上无法连接到mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆