Reputation: 1286
Can anybody say me why this works in mongodb
db.sub_count.update({"subject":"petad","count":1},{$inc:{"count":1}})
But this doesn't work on ruby
sub_count.update({"subject" => "petad", "count"=> 1},{$inc => {"count" => 1}})
where I get the error
/lib/bson/bson_c.rb:24:in `serialize': keys must be strings or symbols (TypeError)
Upvotes: 0
Views: 246
Reputation: 4796
The query should be:
sub_count.update({...}, {"$inc" => {"count" => 1}}) # And not :$inc
$inc
is not a valid symbol (or string) and that's why you see the error.
Aside: I'm not sure if this works: :"$inc"
You can define a symbol this way but there is no mention in the Ruby driver docs that a symbol can be used for the atomic operators and since I haven't tried it at any point, I'm not sure.
Upvotes: 1