Module: Mongoid::Locking::Contextual::Mongo

Defined in:
lib/mongoid/locking/contextual/mongo.rb

Overview

:nodoc:

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#update_documents(attributes, method = :update_one, opts = {}) ⇒ true, false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update the documents for the provided method.

Examples:

Update the documents.

context.update_documents(attrs)

Parameters:

  • attributes (Hash)

    The updates.

  • method (Symbol) (defaults to: :update_one)

    The method to use.

Returns:

  • (true, false)

    If the update succeeded.

Since:

  • 0.1.0



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mongoid/locking/contextual/mongo.rb', line 17

def update_documents(attributes, method = :update_one, opts = {})
  return false unless attributes

  attributes = Hash[attributes.transform_keys { |k| klass.database_field_name(k.to_s) }]
  updates = attributes.__consolidate__(klass)
  if _locking?
    updates["$inc"] ||= {}
    updates["$inc"]["lock_version"] = 1
  end
  view.send(method, updates, opts)
end