Sha256: af5059635d7121715ba4a63be3f3d9c4de9777cfc00dbb569e803c0834b23efb

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

= mongomapper_id2

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

This gem was based on this post http://ihswebdesign.com/blog/autoincrement-in-mongodb-with-ruby/

== Installation

  # https://rubygems.org/gems/mongomapper_id2
  $ sudo gem install mongomapper_id2

=== Adding mongomapper_id2 gem

  # Gemfile
  gem 'mongomapper_id2'

=== Adding mongomapper_id2 in a document

  # app/models/movie.rb
  class Movie
    include MongoMapper::Document
    
    key :title, String 
    # Here is the mongomapper_id2
    auto_increment!
  end

== Usage

  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

== Overriding the default id

If you want to override the default id, just add the option ":override => true"

  # app/models/movie.rb
  class Movie
    include MongoMapper::Document
  
    key :title, String 
    # Here is the mongomapper_id2
    auto_increment! :override => true
  end

Activating this option the default id will be replaced by an auto incremented id

  movie = Movie.create(:title => 'Pirates of Silicon Valley')
  movie.id # 1

== Do you want to improve mongomapper_id2

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

=== Development

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

==== Test

  $ rake test

== Copyright

See LICENSE for details

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongomapper_id2-0.0.5 README.rdoc