首页 > 解决方案 > 无法在 Gatsby 项目中连接 MongoDb Atlas

问题描述

我使用 Gatsby 和 MongoDb Atlas。我可以从 Compass 或任何其他客户端连接我的 MongoDb。但是,我无法从 Gatsby 连接。我总是出错。

我尝试了很多东西来解决这个问题。我从 MongoDb Atlas 的网络访问中删除了所有 IP 地址,并尝试不使用 IP 地址,它不起作用。然后,我只尝试 0.0.0.0 Ip,没有任何改变。然后我清除所有 npm 包并尝试,但一切都是一样的。

MongoServerSelectionError: connection <monitor> to 54.93.42.35:27017 closed
    at Timeout._onTimeout (E:\Kisisel\gatsbyTest\node_modules\mongodb\lib\core\sdam\topology.js:438:30)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map {
      'cluster0-shard-00-00.tl25n.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-02.tl25n.mongodb.net:27017' => [ServerDescription],
      'cluster0-shard-00-01.tl25n.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  }
}

我的连接字符串:

mongodb+srv://<username>:<password>@cluster0.tl25n.mongodb.net/<dbName>?retryWrites=true&ssl=true

Compass 上的相同连接字符串: 在此处输入图像描述

网络访问: 在此处输入图像描述

标签: node.jsmongodbgatsby

解决方案


推荐阅读