Permalink
Browse files

avoid sending an empty atomic update to mongo

  • Loading branch information...
1 parent eda7801 commit 45c4d1ea7e6f2ca7af27b47f42bfceeb6f81cd26 @mislav committed Apr 26, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/mingo/persistence.rb
@@ -25,7 +25,10 @@ def persisted?
def save(options = {})
if persisted?
- update(values_for_update, options)
+ hash = values_for_update
+ unless %w[$set $unset] == hash.keys && hash.values.all? { |v| v.empty? }
+ update(hash, options)
+ end
else
self['_id'] = self.class.collection.insert(self.to_hash, options)
end

0 comments on commit 45c4d1e

Please sign in to comment.