https://github.com/phstc/mongomapper_id2
It’s a MongoMapper’s plugin to add auto incremented ids in MongoMapper’s documents.
https://github.com/phstc/mongomapper_id2
Last synced: about 1 year ago
JSON representation
It’s a MongoMapper’s plugin to add auto incremented ids in MongoMapper’s documents.
- Host: GitHub
- URL: https://github.com/phstc/mongomapper_id2
- Owner: phstc
- License: mit
- Created: 2010-12-30T20:55:07.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2013-12-21T22:32:22.000Z (over 12 years ago)
- Last Synced: 2024-04-25T18:00:31.362Z (about 2 years ago)
- Language: Ruby
- Homepage:
- Size: 146 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE
Awesome Lists containing this project
README
= mongomapper_id2
It’s a MongoMapper’s plugin to add auto incremented ids 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
$ gem install mongomapper_id2
or
# Gemfile
gem 'mongomapper_id2'
== Usage
# 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
=== Overriding the document's id `:override => true`
# app/models/movie.rb
class Movie
include MongoMapper::Document
key :title, String
auto_increment! :override => true
end
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
$ bundle install
$ bundle exec rake
==== Test
$ bundle exec rake test
== Copyright
See LICENSE for details