Skip to content

anymoto/mongomapper_id2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

It’s a MongoMapper’s plugin to add auto incremented id to your MongoMapper’s documents

This gem is inspired in this blog post ihswebdesign.com/blog/autoincrement-in-mongodb-with-ruby/

# https://rubygems.org/gems/mongomapper_id2
$ sudo gem install mongomapper_id2
# Gemfile
gem 'mongomapper_id2'
# app/models/movie.rb
class Movie
  include MongoMapper::Document

  key :title, String 
  # Here is the mongomapper_id2
  auto_increment!
end
movie = Movie.create(:title => 'The Simpsons Movie')
movie.id # BSON::ObjectId('4d1d150d30f2246bc6000001')
# Here is the mongomapper_id2
movie.id2 # 1

movie2 = Movie.create(:title => 'Pirates of Silicon Valley')
movie2.id2 # 2

You’re welcome to make your contributions and send them as a pull request

pablocantero.com/blog/contato

$ gem install bundler (if you don't have it)
$ bundle install
$ bundle exec rake
$ rake test

See LICENSE for details

About

It’s a MongoMapper's plugin to add auto incremented id to your MongoMapper's documents

Resources

License

Stars

Watchers

Forks

Packages

No packages published