-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I'm incrementing a field I've defined as BigDecimal:
field :balance, type: BigDecimal, default: 0
So I figured the most appropriate thing to do is convert the value to BigDecimal before passing it to #inc:
def increment(amount)
self.inc(:balance, amount.to_d * 100)
end
But I get the following error:
NoMethodError:
undefined method `bson_dump' for #<BigDecimal:29563f0,'0.1E6',9(36)>
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/extensions/hash.rb:36:in `block in bson_dump'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/extensions/hash.rb:35:in `each'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/extensions/hash.rb:35:in `bson_dump'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/extensions/hash.rb:36:in `block in bson_dump'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/extensions/hash.rb:35:in `each'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/extensions/hash.rb:35:in `bson_dump'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/bson/document.rb:11:in `serialize'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/protocol/message.rb:136:in `serialize_update'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/protocol/message.rb:289:in `serialize'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/connection.rb:137:in `block in write'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/connection.rb:135:in `each'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/connection.rb:135:in `write'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:518:in `block (2 levels) in flush'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:113:in `ensure_connected'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:517:in `block in flush'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:532:in `logging'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:516:in `flush'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:505:in `process'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:422:in `update'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/session/context.rb:76:in `block in update'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/session/context.rb:109:in `block in with_node'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/cluster.rb:139:in `block in with_primary'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/node.rb:158:in `ensure_primary'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/cluster.rb:138:in `with_primary'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/session/context.rb:108:in `with_node'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/session/context.rb:69:in `update'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/query.rb:305:in `block in update'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/session.rb:264:in `with'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/moped-1.1.3/lib/moped/query.rb:304:in `update'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.1/lib/mongoid/persistence/atomic/operation.rb:97:in `execute'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.1/lib/mongoid/persistence/atomic/inc.rb:22:in `block in persist'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.1/lib/mongoid/persistence/atomic/operation.rb:78:in `prepare'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.1/lib/mongoid/persistence/atomic/inc.rb:19:in `persist'
- /home/ofer/.rvm/gems/ruby-1.9.3-p194/gems/mongoid-3.0.1/lib/mongoid/persistence/atomic.rb:82:in `inc'
- ./lib/mcbooks/ledger/base.rb:64:in `increment'