model.find({}) 在我将超时设置为 5 分钟时没有响应,但在超时为 1 分钟时它会响应
model.find({}) is not responding when I give the timeout as 5 minutes but it responds when the timeout is of 1 minute
我正在使用 mongoose 列出 mongodb 中集合中的所有数据,但我希望响应在 5 分钟后出现,但当超时值为 5 分钟时它没有响应,但它在超时时响应1分钟
router.get(routeIdentifier+'/list/:id', function(req, res, next) {
model.find({}, function (err, objects) {
setTimeout(function(){
if (err) return res.send(err);
objects.push({id:req.params.id})
return res.json(objects);
},300000)
});
})
;
据我所知,这主要是由于 HTTP 服务器超时。在从数据库 model
发送响应之前超时。
根据此处的文档,默认超时为 2 分钟:https://nodejs.org/dist/latest-v9.x/docs/api/http.html#http_server_settimeout_msecs_callback
请注意 ExpressJS
位于 built-in NodeJS HTTP 服务器的顶部。
尝试以下操作:
let server = http.createServer( expressApp );
server.setTimeout( 300000 );
这会将 HTTP-Server 超时初始化为 5 分钟。
我正在使用 mongoose 列出 mongodb 中集合中的所有数据,但我希望响应在 5 分钟后出现,但当超时值为 5 分钟时它没有响应,但它在超时时响应1分钟
router.get(routeIdentifier+'/list/:id', function(req, res, next) {
model.find({}, function (err, objects) {
setTimeout(function(){
if (err) return res.send(err);
objects.push({id:req.params.id})
return res.json(objects);
},300000)
});
})
;
据我所知,这主要是由于 HTTP 服务器超时。在从数据库 model
发送响应之前超时。
根据此处的文档,默认超时为 2 分钟:https://nodejs.org/dist/latest-v9.x/docs/api/http.html#http_server_settimeout_msecs_callback
请注意 ExpressJS
位于 built-in NodeJS HTTP 服务器的顶部。
尝试以下操作:
let server = http.createServer( expressApp );
server.setTimeout( 300000 );
这会将 HTTP-Server 超时初始化为 5 分钟。