Module: Mongoid::Locking::Contextual::Atomic
- Defined in:
- lib/mongoid/locking/contextual/atomic.rb
Overview
:nodoc:
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.
26 27 28 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 26 def add_each_to_set(adds) _update_many_with_locking("$addToSet" => collect_each_operations(adds)) end |
#add_to_set(adds) ⇒ nil
Execute an atomic $addToSet on the matching documents.
14 15 16 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 14 def add_to_set(adds) _update_many_with_locking("$addToSet" => collect_operations(adds)) end |
#bit(bits) ⇒ nil
Perform an atomic $bit operation on the matching documents.
38 39 40 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 38 def bit(bits) _update_many_with_locking("$bit" => collect_operations(bits)) end |
#inc(incs) ⇒ nil
Perform an atomic $inc operation on the matching documents.
50 51 52 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 50 def inc(incs) _update_many_with_locking("$inc" => collect_operations(incs)) end |
#pop(pops) ⇒ nil
Perform an atomic $pop operation on the matching documents.
65 66 67 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 65 def pop(pops) _update_many_with_locking("$pop" => collect_operations(pops)) end |
#pull(pulls) ⇒ nil
Expression pulling is not yet supported.
Perform an atomic $pull operation on the matching documents.
79 80 81 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 79 def pull(pulls) _update_many_with_locking("$pull" => collect_operations(pulls)) end |
#pull_all(pulls) ⇒ nil
Perform an atomic $pullAll operation on the matching documents.
91 92 93 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 91 def pull_all(pulls) _update_many_with_locking("$pullAll" => collect_operations(pulls)) end |
#push(pushes) ⇒ nil
Perform an atomic $push operation on the matching documents.
103 104 105 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 103 def push(pushes) _update_many_with_locking("$push" => collect_operations(pushes)) end |
#push_all(pushes) ⇒ nil
Perform an atomic $push/$each operation on the matching documents.
115 116 117 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 115 def push_all(pushes) _update_many_with_locking("$push" => collect_each_operations(pushes)) end |
#rename(renames) ⇒ nil
Perform an atomic $rename of fields on the matching documents.
127 128 129 130 131 132 133 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 127 def rename(renames) operations = renames.inject({}) do |ops, (old_name, new_name)| ops[old_name] = new_name.to_s ops end _update_many_with_locking("$rename" => collect_operations(operations)) end |
#set(sets) ⇒ nil
Perform an atomic $set of fields on the matching documents.
145 146 147 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 145 def set(sets) _update_many_with_locking("$set" => collect_operations(sets)) end |
#unset(*args) ⇒ nil
Perform an atomic $unset of a field on the matching documents.
160 161 162 163 164 165 |
# File 'lib/mongoid/locking/contextual/atomic.rb', line 160 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 |