【问题标题】:Mongodb / Mongoose, can only update limited (6) number of documents before it freezesMongodb / Mongoose,在冻结之前只能更新有限(6)个文档
【发布时间】:2015-02-10 19:17:59
【问题描述】:

我正在使用 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);
      });
    }
  });
});

在角度方面,每当我尝试连续发出超过 6 个推送(更新)请求时,节点程序都会冻结(没有更新,没有记录发布请求)一两分钟,然后发布请求是已收到。发生这种情况有什么原因吗?当节点冻结时,没有任何工作(它不提供请求)但不会崩溃。

这里是一个快递日志的例子:

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 }

【问题讨论】:

    标签: angularjs node.js mongodb mongoose


    【解决方案1】:

    在 node.js 中,打开的套接字的最大数量是五个(0.12 版之前,本周五发布)... 在这里,您似乎没有在更新的情况下关闭请求...... 也许您的第一个请求需要超时才能接受下一个请求?

    在这种情况下只需添加一个 res.status(200).end() ? (不确定语法) 如果这不起作用,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-04
      • 2011-12-07
      • 2021-03-26
      • 2016-10-15
      • 2020-12-04
      • 1970-01-01
      • 2017-01-06
      • 1970-01-01
      相关资源
      最近更新 更多