Method: Mongoid::Atomic::Modifiers#add_to_set

Defined in:
lib/mongoid/atomic/modifiers.rb

#add_to_set(modifications) ⇒ Object

Add the atomic $addToSet modifiers to the hash.

Examples:

Add the $addToSet modifiers.

modifiers.add_to_set({ "preference_ids" => [ "one" ] })

Parameters:

  • modifications (Hash)

    The add to set modifiers.

Since:

  • 2.4.0

[View source]

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

def add_to_set(modifications)
  modifications.each_pair do |field, value|
    if add_to_sets.has_key?(field)
      value.each do |val|
        add_to_sets[field]["$each"].push(val)
      end
    else
      add_to_sets[field] = { "$each" => value }
    end
  end
end