Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generate unique token in a Mongoid field. Mongoid version of Ryan Bates uniquify gem.

gem install mongoid_uniquify

In your Gemfile

gem "mongoid_uniquify"
  • mongoid 2.0.0 or later

class Project
  include Mongoid::Document
  include Mongoid::Uniquify

  uniquify :token, :length => 7, :chars => ('a'..'z').to_a + ('0'..'9').to_a

  field :token, :type => String

  # ...
end

If you want to use generated token as key and add unique index, do something like below.

class Project
  include Mongoid::Document
  include Mongoid::Uniquify

  uniquify :token, :length => 7, :chars => ('a'..'z').to_a + ('0'..'9').to_a

  field :token, :type => String
  key :token

  index :token, :unique => true

  # ...
end

Copyright © 2011 Kichiro IKEMOTO. See LICENSE.txt for further details.

About

Generate unique token in a Mongoid field. Mongoid version of Ryan Bates uniquify gem.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages