Module: Mongoid::Contextual::Atomic
- Defined in:
- lib/mongoid/contextual/atomic.rb
Instance Method Summary collapse
-
#add_each_to_set(adds) ⇒ nil
Perform an atomic $addToSet/$each on the matching documents.
-
#add_to_set(adds) ⇒ nil
Execute an atomic $addToSet on the matching documents.
-
#bit(bits) ⇒ nil
Perform an atomic $bit operation on the matching documents.
-
#inc(incs) ⇒ nil
Perform an atomic $inc operation on the matching documents.
-
#pop(pops) ⇒ nil
Perform an atomic $pop operation on the matching documents.
-
#pull(pulls) ⇒ nil
Perform an atomic $pull operation on the matching documents.
-
#pull_all(pulls) ⇒ nil
Perform an atomic $pullAll operation on the matching documents.
-
#push(pushes) ⇒ nil
Perform an atomic $push operation on the matching documents.
-
#push_all(pushes) ⇒ nil
Perform an atomic $push/$each operation on the matching documents.
-
#rename(renames) ⇒ nil
Perform an atomic $rename of fields on the matching documents.
-
#set(sets) ⇒ nil
Perform an atomic $set of fields on the matching documents.
-
#unset(*args) ⇒ nil
Perform an atomic $unset of a field on the matching documents.
Instance Method Details
#add_each_to_set(adds) ⇒ nil
Perform an atomic $addToSet/$each on the matching documents.
27 28 29 |
# File 'lib/mongoid/contextual/atomic.rb', line 27 def add_each_to_set(adds) view.update_many("$addToSet" => collect_each_operations(adds)) end |
#add_to_set(adds) ⇒ nil
Execute an atomic $addToSet on the matching documents.
15 16 17 |
# File 'lib/mongoid/contextual/atomic.rb', line 15 def add_to_set(adds) view.update_many("$addToSet" => collect_operations(adds)) end |
#bit(bits) ⇒ nil
Perform an atomic $bit operation on the matching documents.
39 40 41 |
# File 'lib/mongoid/contextual/atomic.rb', line 39 def bit(bits) view.update_many("$bit" => collect_operations(bits)) end |
#inc(incs) ⇒ nil
Perform an atomic $inc operation on the matching documents.
51 52 53 |
# File 'lib/mongoid/contextual/atomic.rb', line 51 def inc(incs) view.update_many("$inc" => collect_operations(incs)) end |
#pop(pops) ⇒ nil
Perform an atomic $pop operation on the matching documents.
66 67 68 |
# File 'lib/mongoid/contextual/atomic.rb', line 66 def pop(pops) view.update_many("$pop" => collect_operations(pops)) end |
#pull(pulls) ⇒ nil
Expression pulling is not yet supported.
Perform an atomic $pull operation on the matching documents.
80 81 82 |
# File 'lib/mongoid/contextual/atomic.rb', line 80 def pull(pulls) view.update_many("$pull" => collect_operations(pulls)) end |
#pull_all(pulls) ⇒ nil
Perform an atomic $pullAll operation on the matching documents.
92 93 94 |
# File 'lib/mongoid/contextual/atomic.rb', line 92 def pull_all(pulls) view.update_many("$pullAll" => collect_operations(pulls)) end |
#push(pushes) ⇒ nil
Perform an atomic $push operation on the matching documents.
104 105 106 |
# File 'lib/mongoid/contextual/atomic.rb', line 104 def push(pushes) view.update_many("$push" => collect_operations(pushes)) end |
#push_all(pushes) ⇒ nil
Perform an atomic $push/$each operation on the matching documents.
116 117 118 |
# File 'lib/mongoid/contextual/atomic.rb', line 116 def push_all(pushes) view.update_many("$push" => collect_each_operations(pushes)) end |
#rename(renames) ⇒ nil
Perform an atomic $rename of fields on the matching documents.
128 129 130 131 132 133 134 |
# File 'lib/mongoid/contextual/atomic.rb', line 128 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 |
#set(sets) ⇒ nil
Perform an atomic $set of fields on the matching documents.
144 145 146 |
# File 'lib/mongoid/contextual/atomic.rb', line 144 def set(sets) view.update_many("$set" => collect_operations(sets)) end |
#unset(*args) ⇒ nil
Perform an atomic $unset of a field on the matching documents.
159 160 161 162 163 164 |
# File 'lib/mongoid/contextual/atomic.rb', line 159 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 |