I need to remove sub-docs from collection
tasks = item.tasks; // item is mongodb collection element, tasks is array of sub docs
tasks.forEach(function(task){
if (!task.finished)
tasks.remove(task)
})
item.save()
after that I get situation when not all sub-docs with finished==true are removed.
Is there the other more correct way to do what I need?
You can do this atomically using an
updatewith the$pulloperator:Seems you could also do this with
MongooseArray#pullbut the docs on that are so thin I’ve never figured out how to use it.