I had this query in Mongoid2 that was working fine:
GlobalWord.collection.update({"_id" => "foo"}, {"$inc" => {:count => 1}}, :upsert => true)
If it finds the GlobalWord with the id foo, then it updates its count by one, otherwise it creates a document with the id foo and a count of one. I didn’t find an equivalent for that in mongoid3.
edit: I need the query to be atomic
I used
GlobalWord.create(:id => word).inc(:count, 1)
which seems to be atomic