Module: Mongoid::Contextual::Atomic
- Defined in:
- lib/mongoid/contextual/atomic.rb
Instance Method Summary collapse
-
#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 $pushAll 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_to_set(adds) ⇒ nil
Execute an atomic $addToSet on the matching documents.
16 17 18 |
# File 'lib/mongoid/contextual/atomic.rb', line 16 def add_to_set(adds) query.update_all("$addToSet" => collect_operations(adds)) end |
#bit(bits) ⇒ nil
Perform an atomic $bit operation on the matching documents.
30 31 32 |
# File 'lib/mongoid/contextual/atomic.rb', line 30 def bit(bits) query.update_all("$bit" => collect_operations(bits)) end |
#inc(incs) ⇒ nil
Perform an atomic $inc operation on the matching documents.
44 45 46 |
# File 'lib/mongoid/contextual/atomic.rb', line 44 def inc(incs) query.update_all("$inc" => collect_operations(incs)) end |
#pop(pops) ⇒ nil
Perform an atomic $pop operation on the matching documents.
61 62 63 |
# File 'lib/mongoid/contextual/atomic.rb', line 61 def pop(pops) query.update_all("$pop" => collect_operations(pops)) end |
#pull(pulls) ⇒ nil
Expression pulling is not yet supported.
Perform an atomic $pull operation on the matching documents.
77 78 79 |
# File 'lib/mongoid/contextual/atomic.rb', line 77 def pull(pulls) query.update_all("$pull" => collect_operations(pulls)) end |
#pull_all(pulls) ⇒ nil
Perform an atomic $pullAll operation on the matching documents.
91 92 93 |
# File 'lib/mongoid/contextual/atomic.rb', line 91 def pull_all(pulls) query.update_all("$pullAll" => collect_operations(pulls)) end |
#push(pushes) ⇒ nil
Perform an atomic $push operation on the matching documents.
105 106 107 |
# File 'lib/mongoid/contextual/atomic.rb', line 105 def push(pushes) query.update_all("$push" => collect_operations(pushes)) end |
#push_all(pushes) ⇒ nil
Perform an atomic $pushAll operation on the matching documents.
119 120 121 |
# File 'lib/mongoid/contextual/atomic.rb', line 119 def push_all(pushes) query.update_all("$pushAll" => collect_operations(pushes)) end |
#rename(renames) ⇒ nil
Perform an atomic $rename of fields on the matching documents.
133 134 135 136 137 138 139 |
# File 'lib/mongoid/contextual/atomic.rb', line 133 def rename(renames) operations = renames.inject({}) do |ops, (old_name, new_name)| ops[old_name] = new_name.to_s ops end query.update_all("$rename" => collect_operations(operations)) end |
#set(sets) ⇒ nil
Perform an atomic $set of fields on the matching documents.
151 152 153 |
# File 'lib/mongoid/contextual/atomic.rb', line 151 def set(sets) query.update_all("$set" => collect_operations(sets)) end |
#unset(*args) ⇒ nil
Perform an atomic $unset of a field on the matching documents.
165 166 167 168 |
# File 'lib/mongoid/contextual/atomic.rb', line 165 def unset(*args) fields = args.__find_args__.collect { |f| [database_field_name(f), true] } query.update_all("$unset" => Hash[fields]) end |