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.
You should be able to do this with a
$pullor a$pullAll(as described here: http://www.mongodb.org/display/DOCS/Updating#Updating-%24pull). E.g., in the shell:This updates all documents by pulling the passedString from the arrField array, if it exists. (
falsefor no upsert,trueto update multiple docs.)