【发布时间】: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