The documentation for the MongoDB update method states the following:
multi - indicates if all documents matching criteria should be updated rather than just one. Can be useful with the $ operators below.
So basically the multi
parameter is what enables the update_all
behaviour in the question you linked to.
In answer to your second question: yes - Mongoid has this feature built in now. The documentation reference is here. But you can use it like this:
User.where(:gender => "Male").update_all(:title => "Mr")
Update
In the case where you want to push a value onto an array field, you'll still need to use the MongoDB library directly, since the Mongoid update_all
method only supports the $set
database update method (which can be used to update an entire array, but not push values onto it).
The example in the answer to the question you linked to would work, I have copied it below those who stumble across this question (thanks shingara!):
User.collection.update(
{'$in' => {:gender => 'Male'}},
{'$push' => {:titles => 'Mr'}},
{:multi => true}
)