删除集合的所有嵌套文档

时间:2013-10-19 02:50:22

标签: node.js mongodb mongoose

我试图删除所有嵌套文档而不只是一个。

这是代码:

        //find and remove all of the embedded workorder units
    db.workorders.find({units: { $ne: null } }, function(err, wos) {

      console.log(wos);
      console.log("removing the embedded workorder units");
      _.each(wos, function(wo) {

        wo.units.remove();
      });

      setTimeout(function() { next() }, 2000);

    });

1 个答案:

答案 0 :(得分:2)

我明白了:

        //find and remove all of the embedded workorder units
    db.workorders.update({}, { $set: { units: [] } }, { multi: true }, function(err) {

      console.log("removing the embedded workorder units");

      next();

    });
相关问题