Method: Mongoid::Contextual::Atomic#unset

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

#unset(*args) ⇒ nil

Perform an atomic $unset of a field on the matching documents.

Examples:

Unset the field on the matches.

context.unset(:name)

Parameters:

  • fields (String, Symbol, Array)

    The name of the fields.

Returns:

  • (nil)

    Nil.

Since:

  • 3.0.0



165
166
167
168
# File 'lib/mongoid/contextual/atomic.rb', line 165

def unset(*args)
  fields = args.__find_args__.collect { |f| [database_field_name(f), true] }
  view.update_many("$unset" => Hash[fields])
end