MongooseError [MongooseServerSelectionError]:连接< monitor>至52.6.250.237:27017关闭 [英] MongooseError [MongooseServerSelectionError]: connection <monitor> to 52.6.250.237:27017 closed

查看:238
本文介绍了MongooseError [MongooseServerSelectionError]:连接< monitor>至52.6.250.237:27017关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过post方法将数据保存在mongodb中,并将mongodb atala与node.js结合使用,但它一直给我一个错误,我提供了正确的连接字符串和正确的密码.请就此问题提供帮助.谢谢

i am trying to save data in mongodb through post method and using mongodb atala with node.js but it keeps giving me an error, i provided correct connection string and correct password. please help in regarding this issue. thanks

here is the code:
const mongoose = require('mongoose');

const monngodb_url="mongodb+srv://maarij:asdf360@cluster0-j7wis.mongodb.net/authDB?retryWrites=true&w=majority";

mongoose.connect(monngodb_url, {useNewUrlParser: true,useUnifiedTopology: true}).then(()=>{
    console.log("mongodb is connected");
}).catch((error)=>{
    console.log("mondb not connected");
    console.log(error);
});

here is Error:

server is running on port 3000
{ name: 'myName', email: 'e@mail.com', password: 'abcdefg' }
mondb not connected
MongooseError [MongooseServerSelectionError]: connection <monitor> to 52.6.250.237:27017 closed
    at new MongooseServerSelectionError (D:\react-native\reactNativeBackend\node_modules\mongoose\lib\error\serverSelection.js:22:11)
    at NativeConnection.Connection.openUri (D:\react-native\reactNativeBackend\node_modules\mongoose\lib\connection.js:808:32)
    at Mongoose.connect (D:\react-native\reactNativeBackend\node_modules\mongoose\lib\index.js:333:15)
    at Object.<anonymous> (D:\react-native\reactNativeBackend\db\db.js:5:10)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (D:\react-native\reactNativeBackend\index.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10) {
  message: 'connection <monitor> to 52.6.250.237:27017 closed',
  name: 'MongooseServerSelectionError',
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster0-shard-00-01-j7wis.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-02-j7wis.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-00-j7wis.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  },
  [Symbol(mongoErrorContextSymbol)]: {}
}

推荐答案

您可以通过进入网络访问面板来解决此问题

然后单击添加IP地址

&然后填充0.0.0.0/0,然后单击确认

不要在生产中这样做,但是在开发中,它将起作用

Don't Do this in Production But in Development, it will Work

这篇关于MongooseError [MongooseServerSelectionError]:连接&lt; monitor&gt;至52.6.250.237:27017关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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