-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Ruby Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Currently the Mongoid::Document#atomically allows you to batch atomic actions into a single database call:
doc = Person.all.first doc.atomically do doc.inc(:age) doc.set(name: "Bob") doc.unset(:shoe_size) end #=> one database call here
It is also currently possible to call these same atomic methods on Mongoid::Criteria scopes, with multiple database calls:
criteria = Person.gt(shoe_size: 9)
# 3 separate database calls below
criteria.inc(:age)
criteria.set(name: "Bob")
criteria.unset(:shoe_size)
As an enhancement I would like to be able to call atomically on the criteria scope, i.e.;
criteria = Person.all.gt(shoe_size: 9) criteria.atomically do doc.inc(:age) doc.set(name: "Bob") doc.unset(:shoe_size) end #=> one database call here
This is not supported today:
Person.all.atomically #=> undefined method 'atomically' for an instance of Mongoid::Criteria (NoMethodError)