Class: Mongoid::Persistence::Atomic::Unset

Inherits:
Object
  • Object
show all
Includes:
Operation
Defined in:
lib/mongoid/persistence/atomic/unset.rb

Overview

Performs atomic $unset operations.

Instance Attribute Summary

Attributes included from Operation

#document, #field, #options, #value

Instance Method Summary collapse

Methods included from Operation

#collection, #initialize, #operation, #path, #prepare

Instance Method Details

#persistnil

Sends the atomic $unset operation to the database.

Examples:

Persist the new values.

unset.persist

Returns:

  • (nil)

    The new value.

Since:

  • 2.1.0



18
19
20
21
22
23
24
# File 'lib/mongoid/persistence/atomic/unset.rb', line 18

def persist
  prepare do
    document.attributes.delete(field)
    collection.update(document.atomic_selector, operation("$unset"), options)
    document.remove_change(value)
  end
end