Mongodb / Mongoose,在冻结之前只能更新有限 (6) 个文档
Mongodb / Mongoose, can only update limited (6) number of documents before it freezes
我正在使用 MEAN 堆栈制作一个 angular 应用程序。我的快递应用程序中有以下代码:
router.post('/', function (req, res) {
var username = req.user.username;
var items = req.body.items;
if (items) {
items = JSON.parse(items);
} else {
return
}
if (!username) {
res.status(401).send('There is no username');
return
}
User.findOne({username: username}, function (err, user) {
if (err) {
throw err;
}
if (!user) {
res.status(401).send('No user with that username');
}
if (typeof items === 'number') {
console.log('yes');
user.update({$push: {cart: items}}, {}, function (err, user, ob) {
console.log('update', err, user, ob);
});
} else {
user.update({$pushAll: {cart: items}}, {}, function (err, user, ob) {
console.log('update', err, user, ob);
});
}
});
});
在angular方面,每当我尝试连续发出超过6个推送(更新)请求时,节点程序就会冻结,(没有更新,没有记录任何post请求),因为一两分钟,然后收到 post 请求。发生这种情况有什么原因吗?当节点冻结时没有任何工作(它不提供任何请求)但不会崩溃。
这里是快递日志的例子:
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
// Very long pause
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
在node.js中,打开socket的最大数量为5个(0.12之前的版本,本周五发布)...
在这里,您似乎没有在更新的情况下关闭请求......
也许您的第一个请求需要超时才能接受下一个请求?
在这种情况下只需添加一个 res.status(200).end() 吗? (不确定语法)
如果这不起作用,请告诉我。
我正在使用 MEAN 堆栈制作一个 angular 应用程序。我的快递应用程序中有以下代码:
router.post('/', function (req, res) {
var username = req.user.username;
var items = req.body.items;
if (items) {
items = JSON.parse(items);
} else {
return
}
if (!username) {
res.status(401).send('There is no username');
return
}
User.findOne({username: username}, function (err, user) {
if (err) {
throw err;
}
if (!user) {
res.status(401).send('No user with that username');
}
if (typeof items === 'number') {
console.log('yes');
user.update({$push: {cart: items}}, {}, function (err, user, ob) {
console.log('update', err, user, ob);
});
} else {
user.update({$pushAll: {cart: items}}, {}, function (err, user, ob) {
console.log('update', err, user, ob);
});
}
});
});
在angular方面,每当我尝试连续发出超过6个推送(更新)请求时,节点程序就会冻结,(没有更新,没有记录任何post请求),因为一两分钟,然后收到 post 请求。发生这种情况有什么原因吗?当节点冻结时没有任何工作(它不提供任何请求)但不会崩溃。
这里是快递日志的例子:
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
// Very long pause
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
POST /addproduct - - ms - -
yes
update null 1 { ok: true, n: 1, updatedExisting: true }
在node.js中,打开socket的最大数量为5个(0.12之前的版本,本周五发布)... 在这里,您似乎没有在更新的情况下关闭请求...... 也许您的第一个请求需要超时才能接受下一个请求?
在这种情况下只需添加一个 res.status(200).end() 吗? (不确定语法) 如果这不起作用,请告诉我。