小编Ary*_*yan的帖子

使用Node.js通过其唯一的_id更新多个MongoDB对象

基本上我正在尝试根据其唯一的objectID(_id)更新Mongo数据库上的多个对象.我尝试了以下但他们没有工作:

  var new_arr = [];
  for (var i = 0; i < req.body.length; i++) {
    // req.body is an array received from the POST request.
    new_arr.push({"_id": new mongodb.ObjectID(req.body[i])})
  }
  console.log(new_arr);

  // new_arr is not accepted since an object is expected.
  job_applications.updateMany(
      new_arr
      ,
      {
        $set: {"application_status": "rejected"}
      }, function (err, results) {
        console.log(results);
        console.log(err);
        if (!err) {
          console.log('success with reject');
          res.sendStatus(200);
        }
      }
  );
Run Code Online (Sandbox Code Playgroud)

我也试过以下没有运气.

var job_applications = req.app.locals.job_applications;
  var new_arr = [];
  for (var i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

mongodb node.js mongodb-query

6
推荐指数
1
解决办法
1092
查看次数

标签 统计

mongodb ×1

mongodb-query ×1

node.js ×1