lib/mongo_mapper/plugins/modifiers.rb in mongo_mapper-0.13.0.beta2 vs lib/mongo_mapper/plugins/modifiers.rb in mongo_mapper-0.13.0
- old
+ new
@@ -62,10 +62,22 @@
def pop(*args)
modifier_update('$pop', args)
end
+ def find_and_modify(args)
+ args[:query] = dealias_keys(args[:query]) if args.key? :query
+ args[:update] = dealias_keys(args[:update]) if args.key? :update
+ collection.find_and_modify(args)
+ end
+
+ def upsert(selector, updates, args = {})
+ criteria = dealias_keys(selector)
+ updates = dealias_keys(updates)
+ collection.update(criteria, updates, args)
+ end
+
private
def modifier_update(modifier, args)
criteria, updates, options = criteria_and_keys_from_args(args)
if options
collection.update(criteria, {modifier => updates}, options.merge(:multi => true))
@@ -82,9 +94,10 @@
else
criteria, (updates, options) = args.partition { |a| !a.is_a?(Hash) }
criteria = { :id => criteria }
end
upgrade_legacy_safe_usage!(options)
+ updates = dealias_keys updates
[criteria_hash(criteria).to_hash, updates, options]
end
def upgrade_legacy_safe_usage!(options)