I have an array of hashes like this:
[
{
id: 123,
color: 'red'
},
{
id: 456,
color: 'green'
}
]
I know how to fetch and update one at a time:
params[:my_documents].each do |doc|
MyDocument.find(doc[:id]).update_attributes(color: doc[:color])
end
…but I suspect that the performance is not very good. I'd like to find a way where I can pass the data to Mongoid/MongoDB directly so that I can update each document without having to find and instantiate every document in order to update a few fields.
How can I perform a batch update using Mongoid without having to fetch them first?