Mongoose: How can I update documents with array values matching one item in the array?
mongodb, mongoose, node.js
Solution
You should be able to do this with a `$pull` or a `$pullAll` (as described here: www.mongodb.org/display/DOCS/Updating#Updating-%24pull). E.g., in the shell:
> db.coll.update({}, {$pull : {arrField : passedString}}, false, true);
This updates all documents by pulling the passedString from the arrField array, if it exists. (`false` for no upsert, `true` to update multiple docs.)
Problem
Using Node.js, mongoDB, mongoose: I have a db collection whos records have field of arrays of strings. I need to remove items in the arrays of all records that match a passed string. This involves finding all records which have an array containing match, splicing item from array and saving records back to db. I'm struggling to work out how to do this.