Add support for $inc modifier #8

Merged
merged 2 commits into from Oct 31, 2012

Conversation

Projects
None yet
2 participants

No description provided.

lib/embedded-mongo/backend/collection.rb
@@ -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 }
@gdb

gdb Oct 24, 2012

Owner

If the type of doc[k] is off, should raise:

"Mongo::OperationFailure: 10140: Cannot apply $inc modifier to non-number"

@gdb

gdb Oct 28, 2012

Owner

(To be clear, this will currently raise a Type error -- I would instead raise the Mongo::OperationFailure.)

Jennifer Freitag
Raise OperationFailure when $inc is applied to non-numeric fields
In response to feedback from pull request.

I have added a new commit to raise an OperationFailure and a test that indicates the new behavior. Please let me know if I missed anything else. Thanks!

@@ -4,6 +4,7 @@
require File.join(File.dirname(__FILE__), '../../lib/embedded-mongo')
class InterfaceTest < Test::Unit::TestCase
+ include Mongo
@gdb

gdb Oct 31, 2012

Owner

I prefer not to include namespaces when not needed -- it makes the resulting code a lot harder to trace. No worries though; I'll fix it up.

Owner

gdb commented Oct 31, 2012

LGTM, thanks!

gdb added a commit that referenced this pull request Oct 31, 2012

Merge pull request #8 from jfreitag/master
Add support for $inc modifier

@gdb gdb merged commit 844456d into gdb:master Oct 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment