Mongoose无法连接到My MongoDB Atlas集群中的服务器

bqf10yzr  于 2023-02-18  发布在  Go
关注(0)|答案(1)|浏览(148)

我刚刚创建了一个基于巴黎的Atlus mongo数据库帐户,并添加了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://www.mongodb.com/docs/atlas/security-whitelist/
    at NativeConnection.Connection.openUri (/home/sbfasto/backendfortsmith.sbfasto.com/node_modules/mongoose/lib/connection.js:825:32)
    at /home/sbfasto/backendfortsmith.sbfasto.com/node_modules/mongoose/lib/index.js:411:10
    at /home/sbfasto/backendfortsmith.sbfasto.com/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5
    at new Promise (<anonymous>)
    at promiseOrCallback (/home/sbfasto/backendfortsmith.sbfasto.com/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10)
    at Mongoose._promiseOrCallback (/home/sbfasto/backendfortsmith.sbfasto.com/node_modules/mongoose/lib/index.js:1285:10)
    at Mongoose.connect (/home/sbfasto/backendfortsmith.sbfasto.com/node_modules/mongoose/lib/index.js:410:20)
    at Object.<anonymous> (/home/sbfasto/backendfortsmith.sbfasto.com/app.js:15:10)
    at Module._compile (node:internal/modules/cjs/loader:1165:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    servers: Map(3) {
      'ac-nbyh9mn-shard-00-00.6yz0ajv.mongodb.net:27017' => [ServerDescription],
      'ac-nbyh9mn-shard-00-01.6yz0ajv.mongodb.net:27017' => [ServerDescription],
      'ac-nbyh9mn-shard-00-02.6yz0ajv.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: 'atlas-a81bt4-shard-0',
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}

在此之后,我添加了IP访问任何IP仍然得到相同的错误。谁能告诉我原因?

mongoose.connect("mongodb+srv://popcorn:<password>@fortsmith.6yz0ajv.mongodb.net/?retryWrites=true&w=majority", {
  useNewUrlParser: true,
  useUnifiedTopology: true }).then(() => console.log('mongo connected')).catch(err => console.log(err));

相关问题