我试图删除所有嵌套文档而不只是一个。
这是代码:
//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);
});
答案 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();
});