Class: Mongoid::Persistence::Operations::Upsert

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Persistence::Operations, Upsertion
Defined in:
lib/mongoid/persistence/operations/upsert.rb

Overview

Wraps behaviour for performing upserts in Mongodb. No matter if the document has been modified or not, it will be sent to the db and Mongo will determin whether or not to insert or update.

Instance Attribute Summary

Attributes included from Mongoid::Persistence::Operations

#conflicts, #document, #options

Instance Method Summary collapse

Methods included from Upsertion

#prepare

Methods included from Mongoid::Persistence::Operations

#collection, #deletes, #initialize, insert, #inserts, #notifying_parent?, #parent, remove, #selector, update, #updates, upsert, #validating?

Instance Method Details

#persisttrue

Persist the upsert operation.

Examples:

Execute the upsert.

operation.persist

Returns:

  • (true)

    Always true.

Since:

  • 3.0.0



20
21
22
23
24
# File 'lib/mongoid/persistence/operations/upsert.rb', line 20

def persist
  prepare do
    collection.find(selector).update(document.as_document, [ :upsert ])
  end
end