You can try something like this:
class Article include Mongoid::Document identity :type => Integer before_create :assign_id def to_param id.to_s end private def assign_id self.id = Sequence.generate_id(:article) end end class Sequence include Mongoid::Document field :object field :last_id, type => Integer def self.generate_id(object) @seq=where(:object => object).first || create(:object => object) @seq.inc(:last_id,1) end end
I have not tried this approach (using it with internal identifiers), but I'm sure it should work. Check out my app here: https://github.com/daekrist/Mongologue I have added a "visible" identifier called pid to my posts and comments. I also use a text identifier for the Tag model.
Mike Ivanov
source share