【问题标题】:MongoDB error on connection 'MongoServerSelectionError',连接“MongoServerSelectionError”时出现 MongoDB 错误,
【发布时间】:2020-07-06 01:40:07
【问题描述】:
   const uri = 'mongodb+srv:<username>//:<passwod>@chatapp-qrps3.azure.mongodb.net/test?retryWrites=true&w=majority'

   const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true })

   client.connect(err => {
       console.log(err)
       client.close();
   });

错误是这样的

MongooseError [MongooseServerSelectionError]:连接到 40.79.242.22:27017 关闭 在新的 MongooseServerSelectionError (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/error/serverSelection.js:22:11) 在 NativeConnection.Connection.openUri (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/connection.js:823:32) 在 Mongoose.connect (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/index.js:333:15) 在对象。 (/Users/sherin/Desktop/sherinshaju/reactsocket/app.js:28:4) 在 Module._compile (internal/modules/cjs/loader.js:1147:30) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10) 在 Module.load (internal/modules/cjs/loader.js:996:32) 在 Function.Module._load (internal/modules/cjs/loader.js:896:14) 在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) 在 internal/main/run_main_module.js:17:47 { 消息:'连接到 40.79.242.22:27017 已关闭',名称: 'MongooseServerSelectionError',原因:TopologyDescription { 类型:'ReplicaSetNoPrimary', 设置名称:空, 最大设置版本:空, maxElectionId:空, 服务器:地图(3){ 'chatapp-shard-00-02-qrps3.azure.mongodb.net:27017' => [服务器描述], 'chatapp-shard-00-00-qrps3.azure.mongodb.net:27017' => [服务器描述], 'chatapp-shard-00-01-qrps3.azure.mongodb.net:27017' => [服务器描述] }, 陈旧:虚假, 兼容:真实, 兼容性错误:空, 逻辑会话超时分钟:空, heartbeatFrequencyMS: 10000, 本地阈值MS:15, commonWireVersion: null }, [Symbol(mongoErrorContextSymbol)]: {} }

【问题讨论】:

    标签: javascript node.js reactjs mongodb express


    【解决方案1】:

    我觉得URI的形式应该是这样的:

    const mongoURI = 'mongodb+srv://<username>:<password>.8055@cluster0-mgonm.mongodb.net/test'
    

    我认为您错过了 URI 中的用户名。

    【讨论】:

    • 它不工作我只是使用免费的芒果数据库服务器..但我无法连接到它
    • 我只是忘记在那个抱歉中添加用户名
    • 如果我的回答有助于解决您的问题,请随时接受。
    • 我添加了用户名和密码,也尝试了pem文件连接但仍然无法正常工作
    猜你喜欢
    • 2020-05-20
    • 2020-10-02
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 2020-10-26
    相关资源
    最近更新 更多