gpt4 book ai didi

mongodb - Mongoose 连接抛出 MongooseServerSelectionError

转载 作者:行者123 更新时间:2023-12-03 15:59:15 27 4
gpt4 key购买 nike

我尝试通过 mongoose 驱动程序连接到我的 mongodb Atlas,但它不断抛出 MongooseServerSelectionError,我已经检查了数据库用户的用户名和密码,它是正确的。

这是我的代码:

server running on port 3000
we are connected: { MongooseServerSelectionError: connection timed out
at new MongooseServerSelectionError (/home/ateyib/UCSD-classes/CSE 135/hw3/node_modules/mongoose/lib/error/serverSelection.js:22:11)
at NativeConnection.Connection.openUri (/home/ateyib/UCSD-classes/CSE 135/hw3/node_modules/mongoose/lib/connection.js:808:32)
at Mongoose.connect (/home/ateyib/UCSD-classes/CSE 135/hw3/node_modules/mongoose/lib/index.js:333:15)
at Object.<anonymous> (/home/ateyib/UCSD-classes/CSE 135/hw3/server.js:17:4)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
at Module.load (internal/modules/cjs/loader.js:630:32)
at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
at Function.Module._load (internal/modules/cjs/loader.js:562:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
at internal/main/run_main_module.js:21:11
message: 'connection timed out',
name: 'MongooseServerSelectionError',
reason:
TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: 'Cluster0-shard-0',
maxSetVersion: null,
maxElectionId: null,
servers:
Map {
'cluster0-shard-00-00-ebets.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-01-ebets.mongodb.net:27017' => [ServerDescription],
'cluster0-shard-00-02-ebets.mongodb.net:27017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: 30,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: 8 },
[Symbol(mongoErrorContextSymbol)]: {} }

最佳答案

这可能与您的 IP 地址有关。转到“网络访问”工具栏选项,单击“编辑”按钮,然后单击“添加当前 IP 地址”并确认。这对我有用。

关于mongodb - Mongoose 连接抛出 MongooseServerSelectionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60420197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com