我得到了错误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
}
}
我的Mongoose代码:
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;
如何修复/绕过此问题?
根据我使用这种eror的经验,我认为您的连接URL有问题。尝试如果您使用windows
或robomongo
,请尝试在MongoDB指南针中使用相同的连接URL。
您也可以尝试检查:
MongoDB连接错误:MongoTimeoutError:服务器选择在30000毫秒后超时
MongoTimeoutError:连接到mongoDB 时,服务器选择在30000毫秒后超时
服务器选择在10000毫秒后超时-无法将Compass连接到localhost 上的mongoDB