Class: Mongoid::Identity
- Inherits:
-
Object
- Object
- Mongoid::Identity
- Defined in:
- lib/mongoid_integer_keys.rb
Instance Method Summary collapse
-
#generate_id ⇒ Object
Generate auto increment id.
Instance Method Details
#generate_id ⇒ Object
Generate auto increment id
4 5 6 7 8 9 10 11 12 |
# File 'lib/mongoid_integer_keys.rb', line 4 def generate_id counter = Mongoid.master.collection("mongoid.auto_increment_ids") table_name = @document.class.to_s.tableize o = counter.find_and_modify({:query => {:_id => table_name}, :update => {:$inc => {:c => 1}}, :new => true, :upsert => true}) o["c"].to_i end |