Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for $inc modifier

  • Loading branch information...
commit 8495e7cdf9a395175036a8250d87f23c1487bb9e 1 parent 06db599
Jennifer Freitag authored
2  lib/embedded-mongo/backend/collection.rb
View
@@ -222,6 +222,8 @@ def apply_update_directive!(directive_key, directive_value, doc)
case directive_key
when '$set'
directive_value.each { |k, v| doc[k] = v }
+ when '$inc'
+ directive_value.each { |k, v| doc[k] += v }
else
raise NotImplementedError.new("Have yet to implement updating: #{directive_key}")
end
15 test/functional/interface_test.rb
View
@@ -61,6 +61,21 @@ def test_update_upsert_record_present
assert_equal 'dee', (entry['tweedle'] rescue nil), 'overwrote unrelated value in record'
end
+ def test_update_increment_record_field
+ selector = {'fubar'=>'rubar'}
+ @foo_collection.insert(
+ selector.merge('baz'=>1)
+ )
+ @foo_collection.update(
+ selector,
+ {'$inc'=>{'baz'=>2}}
+ )
+ cursor = @foo_collection.find(selector)
+ assert_equal 1, cursor.count
+ entry = cursor.first
+ assert_equal 3, (entry['baz'] rescue nil), 'failed to increment value'
+ end
+
def test_update_upsert_record_with_id
@foo_collection.update(
{'foo' => 'bart','_id'=>0xdeadbeef},
Please sign in to comment.
Something went wrong with that request. Please try again.