module Mongoid::Contextual::Atomic

def add_each_to_set(adds)

Returns:
  • (nil) - Nil.

Parameters:
  • adds (Hash) -- The operations.

Other tags:
    Example: Add the value to the set. -
def add_each_to_set(adds)
  view.update_many("$addToSet" => collect_each_operations(adds))
end

def add_to_set(adds)

Returns:
  • (nil) - Nil.

Parameters:
  • adds (Hash) -- The operations.

Other tags:
    Example: Add the value to the set. -
def add_to_set(adds)
  view.update_many("$addToSet" => collect_operations(adds))
end

def bit(bits)

Returns:
  • (nil) - Nil.

Parameters:
  • bits (Hash) -- The operations.

Other tags:
    Example: Perform the bitwise op. -
def bit(bits)
  view.update_many("$bit" => collect_operations(bits))
end

def collect_each_operations(ops)

def collect_each_operations(ops)
  ops.each_with_object({}) do |(field, value), operations|
    operations[database_field_name(field)] = { "$each" => Array.wrap(value).mongoize }
  end
end

def collect_operations(ops)

def collect_operations(ops)
  ops.each_with_object({}) do |(field, value), operations|
    operations[database_field_name(field)] = value.mongoize
  end
end

def inc(incs)

Returns:
  • (nil) - Nil.

Parameters:
  • incs (Hash) -- The operations.

Other tags:
    Example: Perform the atomic increment. -
def inc(incs)
  view.update_many("$inc" => collect_operations(incs))
end

def pop(pops)

Returns:
  • (nil) - Nil.

Parameters:
  • pops (Hash) -- The operations.

Other tags:
    Example: Pop the last value on the matches. -
    Example: Pop the first value on the matches. -
def pop(pops)
  view.update_many("$pop" => collect_operations(pops))
end

def pull(pulls)

Returns:
  • (nil) - Nil.

Parameters:
  • pulls (Hash) -- The operations.

Other tags:
    Note: - Expression pulling is not yet supported.

Other tags:
    Example: Pull the value from the matches. -
def pull(pulls)
  view.update_many("$pull" => collect_operations(pulls))
end

def pull_all(pulls)

Returns:
  • (nil) - Nil.

Parameters:
  • pulls (Hash) -- The operations.

Other tags:
    Example: Pull all the matching values from the matches. -
def pull_all(pulls)
  view.update_many("$pullAll" => collect_operations(pulls))
end

def push(pushes)

Returns:
  • (nil) - Nil.

Parameters:
  • pushes (Hash) -- The operations.

Other tags:
    Example: Push the value to the matching docs. -
def push(pushes)
  view.update_many("$push" => collect_operations(pushes))
end

def push_all(pushes)

Returns:
  • (nil) - Nil.

Parameters:
  • pushes (Hash) -- The operations.

Other tags:
    Example: Push the values to the matching docs. -
def push_all(pushes)
  view.update_many("$push" => collect_each_operations(pushes))
end

def rename(renames)

Returns:
  • (nil) - Nil.

Parameters:
  • renames (Hash) -- The operations.

Other tags:
    Example: Rename the fields on the matching documents. -
def rename(renames)
  operations = renames.inject({}) do |ops, (old_name, new_name)|
    ops[old_name] = new_name.to_s
    ops
  end
  view.update_many("$rename" => collect_operations(operations))
end

def set(sets)

Returns:
  • (nil) - Nil.

Parameters:
  • sets (Hash) -- The operations.

Other tags:
    Example: Set the field value on the matches. -
def set(sets)
  view.update_many("$set" => collect_operations(sets))
end

def unset(*args)

Returns:
  • (nil) - Nil.

Parameters:
  • args (String | Symbol | Array | Hash) --

Other tags:
    Example: Unset the field on the matches. -
def unset(*args)
  fields = args.map { |a| a.is_a?(Hash) ? a.keys : a }
               .__find_args__
               .map { |f| [database_field_name(f), true] }
  view.update_many("$unset" => Hash[fields])
end