class Mongoid::Contextual::FindAndModify

Attributes

criteria[R]

@attribute [r] criteria The criteria for the context. @attribute [r] options The command options. @attribute [r] update The updates. @attribute [r] query The Moped query.

options[R]

@attribute [r] criteria The criteria for the context. @attribute [r] options The command options. @attribute [r] update The updates. @attribute [r] query The Moped query.

query[R]

@attribute [r] criteria The criteria for the context. @attribute [r] options The command options. @attribute [r] update The updates. @attribute [r] query The Moped query.

update[R]

@attribute [r] criteria The criteria for the context. @attribute [r] options The command options. @attribute [r] update The updates. @attribute [r] query The Moped query.

Public Class Methods

new(collection, criteria, update, options = {}) click to toggle source

Initialize the find and modify command, used for MongoDB's $findAndModify.

@example Initialize the command.

FindAndModify.new(criteria, { "$set" => { likes: 1 }})

@param [ Criteria ] criteria The criteria. @param [ Hash ] update The updates. @param [ Hash ] options The command options.

@option options [ true, false ] :new Return the updated document. @option options [ true, false ] :remove Delete the first document. @option options [ true, false ] :upsert Create the document if it doesn't exist.

@since 3.0.0

# File lib/mongoid/contextual/find_and_modify.rb, line 27
def initialize(collection, criteria, update, options = {})
  @collection, @criteria, @options, @update =
    collection, criteria, options, update.mongoize
  @query = collection.find(criteria.selector)
  apply_criteria_options
end

Public Instance Methods

result() click to toggle source

Get the result of the $findAndModify.

@example Get the result.

find_and_modify.result

@return [ Hash ] The result of the command.

@since 3.0.0

# File lib/mongoid/contextual/find_and_modify.rb, line 42
def result
  query.modify(update, options)
end