Joseph Persie III
Joseph Persie III

Reputation: 622

Remove all nested documents of a collection

I am trying to remove all of the nested documents not just one.

here is the code:

        //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);

    });

Upvotes: 0

Views: 68

Answers (1)

Joseph Persie III
Joseph Persie III

Reputation: 622

I figured it out:

        //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();

    });

Upvotes: 2

Related Questions