MongooseServerSelectionError:无法连接到 MongoDB Atlas 集群中的任何服务器

问题描述 投票:0回答:1

MongooseServerSelectionError:无法连接到 MongoDB Atlas 集群中的任何服务器。一个常见原因是您尝试从未列入白名单的 IP 访问数据库。

MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
        at NativeConnection.Connection.openUri (C:\Users\Admin\Desktop\Working\SB\node_modules\mongoose\lib\connection.js:832:32)
        at C:\Users\Admin\Desktop\Working\SB\node_modules\mongoose\lib\index.js:345:10
        at C:\Users\Admin\Desktop\Working\SB\node_modules\mongoose\lib\helpers\promiseOrCallback.js:31:5
        at new Promise (<anonymous>)
        at promiseOrCallback (C:\Users\Admin\Desktop\Working\SB\node_modules\mongoose\lib\helpers\promiseOrCallback.js:30:10)
        at Mongoose._promiseOrCallback (C:\Users\Admin\Desktop\Working\SB\node_modules\mongoose\lib\index.js:1135:10)
        at Mongoose.connect (C:\Users\Admin\Desktop\Working\SB\node_modules\mongoose\lib\index.js:344:20)
        at Object.<anonymous> (C:\Users\Admin\Desktop\Working\SB\app.js:305:10)    at Module._compile (internal/modules/cjs/loader.js:1138:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
        at Module.load (internal/modules/cjs/loader.js:986:32)
        at Function.Module._load (internal/modules/cjs/loader.js:879:14)       
        at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
        at internal/main/run_main_module.js:17:47 {
      reason: TopologyDescription {
        type: 'ReplicaSetNoPrimary',
        setName: null,
        maxSetVersion: null,
        maxElectionId: null,
        servers: Map {
          'smile-shard-00-00.xeyqd.mongodb.net:27017' => [ServerDescription],  
          'smile-shard-00-01.xeyqd.mongodb.net:27017' => [ServerDescription],  
          'smile-shard-00-02.xeyqd.mongodb.net:27017' => [ServerDescription]   
        },
        stale: false,
        compatible: true,
        compatibilityError: null,
        logicalSessionTimeoutMinutes: null,
        heartbeatFrequencyMS: 10000,
        localThresholdMS: 15,
        commonWireVersion: null
      }
    }

我已经将 mongodb 网络访问的 IP 地址更新为 => IP 访问列表为 0.0.0.0/0 但错误仍然发生。我认为这个错误是由于window防火墙而发生的。但我不知道如何解决这个问题。

node.js mongodb windows-firewall
1个回答
0
投票

你好,我认为现在回答已经太晚了,但我希望它能帮助我昨天遇到同样问题的人,我通过创建具有 atlasAdmin 角色的用户解决了这个问题

注意:确保您的网络访问中有您的 IP

© www.soinside.com 2019 - 2024. All rights reserved.