本文介绍了猫鼬没有连接MongoDB Atlas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用MongoDB Atlas与Mongo合作,而在尝试连接时,这是我得到的错误:

This is the first time I use MongoDB Atlas to work with Mongo, and while trying to connect, that's the error I get:

Error: connect ECONNREFUSED 3.209.60.172:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14) {
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {}
}

这是我的代码:

const express = require('express');
const mongoose = require('mongoose');

const app = express();

mongoose.connect('mongodb+srv://johnnybox:<password>@cluster0-cgxqx.mongodb.net/test?retryWrites=true&w=majority', {
  useNewUrlParser: true
}).then(() => console.log('MongoDB Connected...'))
  .catch(err => console.log(err));

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

app.use(require('./routes'));

app.listen(3331);

ps *我没有丢失我的凭据

ps* I'm not missing my credentials

已经在这里寻找解决方案了,但是没有什么比我的问题要解决的了.

Already looked for a solution here but there's nothing similar to my problem.

我的白名单:

推荐答案

我试图在家中运行此代码,并且效果很好!

I tried to run this code at home and it worked perfectly!

所以这是我办公室里的东西,经过一番测试之后,问题出在连接端口被锁住了.

So it was something here in my office, after some testing, the problem was with the connection port that was locked.

看看:

Error: connect ECONNREFUSED 3.209.60.172:27017

请注意,它连接到端口27017

Note that it connects to the port 27017

** Ip是随机的,因此每次请求后都会更改.

**The Ip is random, so it changes after every requisition.

我的SD打开此端口后,一切正常!

After my Sd opened this port, everything worked properly!!

非常感谢您的帮助!

这篇关于猫鼬没有连接MongoDB Atlas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:08