Node.js Mongoose使用ssl连接到副本集群集失败
我有一个带有ssl服务器验证的mongo副本集集群。我怎样才能和猫鼬联系起来Node.js Mongoose使用ssl连接到副本集群集失败,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我有一个带有ssl服务器验证的mongo副本集集群。我怎样才能和猫鼬联系起来 const key = fs.readFileSync(<Path to file>); mongoose.connect(dbConectionString, { sslCA: key, useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, }).then((x) => {
const key = fs.readFileSync(<Path to file>);
mongoose.connect(dbConectionString, {
sslCA: key,
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
}).then((x) => {
console.log('connected');
}).catch((err) => {
console.log(err);
});
这项工作(MongoDB指南针)
此设置的错误消息
connection error: MongooseError [MongooseServerSelectionError]: connection <monitor> to <server-ip>:<server-port> closed
at new MongooseServerSelectionError (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\node_modules\mongoose\lib\error\serverSelection.js:22:11)
at NativeConnection.Connection.openUri (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\node_modules\mongoose\lib\connection.js:823:32)
at Mongoose.connect (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\node_modules\mongoose\lib\index.js:333:15)
at new DBConection (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\.build\src\config\db\connection.js:13:28)
at Server.dbConfig (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\.build\src\server.js:31:20)
at new Server (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\.build\src\server.js:18:14)
at Function.bootstrap (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\.build\src\server.js:24:16)
at Object.<anonymous> (D:\git_repos\WirVsVirus\Coronahelfer-Hackathon\.build\src\server.js:36:23)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
message: 'connection <monitor> to <server-ip>:<server-port> closed',
name: 'MongooseServerSelectionError',
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'<server-ip>:<server-port>' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
},
[Symbol(mongoErrorContextSymbol)]: {}
}
连接错误:MongooseError[MongooseServerSelectionError]:连接到:已关闭
新MongooseServerSelectionError(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\node\u modules\mongoose\lib\error\serverSelection.js:22:11)
位于NativeConnection.Connection.openUri(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\node\u modules\mongoose\lib\Connection.js:823:32)
在Mongoose.connect(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\node\u modules\Mongoose\lib\index.js:333:15)
在新的数据库连接(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\.build\src\config\db\connection.js:13:28)
在Server.dbConfig(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\.build\src\Server.js:31:20)
在新服务器上(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\.build\src\Server.js:18:14)
在Function.bootstrap(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\.build\src\server.js:24:16)
反对。(D:\git\u repos\WirVsVirus\Coronahelfer Hackathon\.build\src\server.js:36:23)
at模块编译(内部/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js(internal/modules/cjs/loader.js:1171:10)
在Module.load(内部/modules/cjs/loader.js:1000:32)
at Function.Module._load(内部/modules/cjs/loader.js:899:14)
在Function.executeUserEntryPoint[作为runMain](internal/modules/run_main.js:71:12)
在internal/main/run_main_module.js:17:47{
消息:“连接到:已关闭”,
名称:“MongooseServerSelectionError”,
原因:拓扑学描述{
类型:'Single',
setName:null,
maxSetVersion:null,
maxElectionId:null,
服务器:地图(1){
“:”=>[ServerDescription]
},
陈腐:错,
是的,
兼容性错误:null,
logicalSessionTimeoutMinutes:空,
心跳频率:10000,
localThresholdMS:15,
commonWireVersion:空
},
[符号(mongoErrorContextSymbol)]:{}
}
找到了解决方案。将ssl=true添加到连接字符串中
this.DB_URL = 'mongodb://user:password@ip:port/collection?authSource=admin&ssl=true';
this.DB_URL = 'mongodb://user:password@ip:port/collection?authSource=admin&ssl=true';