I want to update a field of a collection, that actually has a string representation of a date, and change it to an ISODate.
I have a solution already, but It's is inefficient:
class MoveTimestampsFromStringToTimestamp < Mongoid::Migration
def self.up
self[:stats].find({"timestamp"=>{"$type"=>2}}).each do |stat|
stat["timestamp"] = DateTime.parse(stat["timestamp"])
self[:stats].find({_id: stat["_id"]}).update({"$set" => stat})
end
end
end
I would like to update it in one operation instead of search and update for every record.