【发布时间】:2012-03-12 06:22:24
【问题描述】:
所以我读到 mongoose driver 用于 NodeJS 缓存查询,直到它连接到 MongoDB(没有超时)。但是当数据库崩溃时,应该可以向用户发送消息。那么让我们看看这段NodeJS代码:
Users.find({}, function(err, result) {
// Do something with result and send response to the user
});
这可能挂在 infintum 上。因此,解决此问题的一种方法是执行以下操作
var timeout = setTimeout(function() {
// whem we hit timeout, respond to the user with appropriate message
}, 10000);
Users.find({}, function(err, result) {
clearTimeout(timeout); // forget about error
// Do something with result and send response to the user
});
问题是:这是一个好方法吗?内存泄漏(挂起查询到 MongoDB)怎么办?
【问题讨论】:
标签: javascript node.js mongodb timeout mongoose