# MODEL class User include Mongoid::Document field :username field :counter, :default => 0 field :loves, :default => [] index({ :username => 1 }) end # DB SEED FILE marc = User.new marc.username = 'marc' marc.counter = 5 marc.loves = ['a', 'b', 'c'] marc.save # QUERY User.where(:username => 'marc'). update_all( "$inc" => { :counter => -1, }, "$pull" => { :loves => 'b' } ) # RESULT IN DB { "$inc": { "counter": -1 }, "$pull": { "loves": "b" }, "_id": ObjectId("4fe08719bd31e0fbd7000001"), "counter": 5, "loves": { "0": "a", "1": "b", "2": "c" }, "username": "marc" }
I've created a repository for this example if it helps:
https://github.com/marbemac/rails-sandbox
Just run the db seed file and then hit the root url and you should see the behavior.