我有一个远程的mongo服务器,据我所知,我可以正确地连接:
{"t":{"$date":"2020-12-21T15:57:30.022+00:00"},"s":"I", "c":"ACCESS", "id":20250, "ctx":"conn102","msg":"Successful authentication","attr":{"mechanism":"SCRAM-SHA-256","principalName":"test_user","authenticationDatabase":"admin","client":"x.x.x.x:56604"}}
但是当我从我的测试应用程序中检查插入命令时,我会得到一个缓冲超时的。
[nodemon] starting `node ./dist/server.js`
Express server listening on port 3000
MongoDB connected
createUser
----------
err MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms
at Timeout.setTimeout (C:\Users\_jmvelasco\Documents\node-mongodb-setup-test\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:184:20)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
user data undefined
----------
在mongoDB服务器中,我可以在日志中看到这些行:
{"t":{"$date":"2020-12-21T15:57:29.083+00:00"},"s":"W", "c":"NETWORK", "id":4615610, "ctx":"conn90","msg":"Failed to check socket connectivity","attr":{"error":"The operation completed successfully."}}
{"t":{"$date":"2020-12-21T15:57:29.083+00:00"},"s":"I", "c":"-", "id":20883, "ctx":"conn90","msg":"Interrupted operation as its client disconnected","attr":{"opId":92120}}
{"t":{"$date":"2020-12-21T15:57:29.084+00:00"},"s":"I", "c":"NETWORK", "id":22989, "ctx":"conn90","msg":"Error sending response to client. Ending connection from remote","attr":{"error":{"code":6,"codeName":"HostUnreachable","errmsg":"Connection reset by peer"},"remote":"x.x.x.x:56530","connectionId":90}}
{"t":{"$date":"2020-12-21T15:57:29.084+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn90","msg":"Connection ended","attr":{"remote":"x.x.x.x:56530","connectionId":90,"connectionCount":17}}
我不明白我有什么问题。
我的服务器是Win2019,我在默认端口的mongoDB服务器中有入站和出站规则。我将mongodb服务器配置为接受外部连接(bindIp设置为0.0.0.0),并正确设置身份验证,因为我是从webapp获得连接的。但是,当检查POST方法时,我会得到上面描述的错误。
我尝试过围绕不同的超时选项进行操作,但没有成功,我已经将keepAlice设置为true (也在没有检查的情况下)。
private mongoSetup(): void {
var options = {
useNewUrlParser: true,
useUnifiedTopology: true,
keepAlive: true,
};
mongoose.connect(this.mongoUrl, options, function (err, db) {
if (err) {
console.log('MongoDB connect error:', err);
} else {
console.log('MongoDB connected');
}
});
}
* mongoUrl = 'mongodb://test_user:xxxx@x.x.x.x:27017/' +
env.getDBName() +
'?authSource=admin'
我是否需要在应用程序运行的机器上定义防火墙规则(远程mongo客户端)?
我需要在mongo服务器中设置套接字连接吗?
想法?
https://stackoverflow.com/questions/65396271
复制相似问题