【问题标题】:Got the Error "MongooseServerSelectionError: Server selection timed out after 30000 ms"收到错误“MongooseServerSelectionError:服务器选择在 30000 毫秒后超时”
【发布时间】:2020-12-06 08:58:26
【问题描述】:

我收到了错误 MongooseServerSelectionError: Server selection timed out after 30000 ms。 我正在使用 MongoDB Atlas。 我尝试将 useUnifiedTopology 更改为 false 并且我的应用程序没有崩溃,但我收到错误 DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

整个错误信息:

MongooseServerSelectionError: Server selection timed out after 30000 ms
 {
  reason: TopologyDescription {
    type: 'ReplicaSetWithPrimary',
    setName: 'atlas-lhb3t7-shard-0',
    maxSetVersion: 1,
    maxElectionId: 7fffffff0000000000000005,
    servers: Map {
      'wolfgangtest-shard-00-02.q8jpm.mongodb.net:27017' => [ServerDescription],
      'wolfgangtest-shard-00-00.q8jpm.mongodb.net:27017' => [ServerDescription],
      'wolfgangtest-shard-00-01.q8jpm.mongodb.net:27017' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: 8
  }
}

我的猫鼬代码:

const dbOptions = {
            useNewUrlParser: true,
            autoIndex: false,
            poolSize: 5,
            connectTimeoutMS: 10000,
            family: 4,
            useUnifiedTopology: true
        };
        
        mongoose.connect('mongodb+srv://Wolfgang:christian13561z@wolfgangtest.q8jpm.mongodb.net/Wolfgang?retryWrites=true&w=majority', dbOptions);
        mongoose.set('useFindAndModify', false);
        mongoose.Promise = global.Promise;

我该如何解决/绕过这个问题?

【问题讨论】:

    标签: javascript node.js mongodb mongoose


    【解决方案1】:

    根据我遇到这种错误的经验,我认为您的连接 URL 有问题。请尝试 如果您使用 windowsrobomongo,请尝试在 MongoDB 罗盘中使用相同的连接 URL。

    你也可以试试看:

    MongoDB connection error: MongoTimeoutError: Server selection timed out after 30000 ms

    MongoTimeoutError: Server selection timed out after 30000 ms while connecting to mongoDB

    Server selection timed out after 10000 ms - Cannot connect Compass to mongoDB on localhost

    【讨论】:

    • 我做到了,我可以很好地连接到它。
    猜你喜欢
    • 2020-02-22
    • 2020-04-02
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多