Method: Mongoid::Contextual::Atomic#rename

Defined in:
lib/mongoid/contextual/atomic.rb

#rename(renames) ⇒ nil

Perform an atomic $rename of fields on the matching documents.

Examples:

Rename the fields on the matching documents.

context.rename(members: :artists)

Parameters:

  • renames (Hash)

    The operations.

Returns:

  • (nil)

    Nil.

Since:

  • 3.0.0



133
134
135
136
137
138
139
# File 'lib/mongoid/contextual/atomic.rb', line 133

def rename(renames)
  operations = renames.inject({}) do |ops, (old_name, new_name)|
    ops[old_name] = new_name.to_s
    ops
  end
  view.update_many("$rename" => collect_operations(operations))
end