{"id":15642146,"url":"https://github.com/huacnlee/mongoid_auto_increment_id","last_synced_at":"2025-05-07T15:45:50.706Z","repository":{"id":1671341,"uuid":"2398222","full_name":"huacnlee/mongoid_auto_increment_id","owner":"huacnlee","description":"Override id field to MySQL like auto increment for Mongoid.","archived":false,"fork":false,"pushed_at":"2020-12-15T02:45:05.000Z","size":64,"stargazers_count":64,"open_issues_count":4,"forks_count":18,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-02T20:04:48.927Z","etag":null,"topics":["auto-increment","mongodb","mongoid","mongoid-plugin"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huacnlee.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-16T08:51:11.000Z","updated_at":"2024-12-18T03:09:39.000Z","dependencies_parsed_at":"2022-08-20T23:40:36.684Z","dependency_job_id":null,"html_url":"https://github.com/huacnlee/mongoid_auto_increment_id","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fmongoid_auto_increment_id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fmongoid_auto_increment_id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fmongoid_auto_increment_id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huacnlee%2Fmongoid_auto_increment_id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huacnlee","download_url":"https://codeload.github.com/huacnlee/mongoid_auto_increment_id/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252908851,"owners_count":21823509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-increment","mongodb","mongoid","mongoid-plugin"],"created_at":"2024-10-03T11:54:54.027Z","updated_at":"2025-05-07T15:45:50.666Z","avatar_url":"https://github.com/huacnlee.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"This gem for change Mongoid id field as Integer like MySQL.\n\nIdea from MongoDB document: [How to Make an Auto Incrementing Field](http://www.mongodb.org/display/DOCS/How+to+Make+an+Auto+Incrementing+Field)\n\n\u003e NOTE! \n\u003e This Gem has helped [Ruby China](https://ruby-china.org) in pass 4 years，and produce over million rows, it's work very will.\n\u003e In now, Ruby China ([Homeland](https://github.com/ruby-china/homeland)) has changed to ActiveRecord to use PostgreSQL as Database, so may be I don't have time keep this gem compatible with new versions of Mongoid.\n\u003e But even that, I am be sure that this gem still working for Mongoid 5.0 and lower version.\n\n\n## Status\n\n- [![Gem Version](https://badge.fury.io/rb/mongoid_auto_increment_id.svg)](https://rubygems.org/gems/mongoid_auto_increment_id)\n- [![CI Status](https://api.travis-ci.org/huacnlee/mongoid_auto_increment_id.svg)](http://travis-ci.org/huacnlee/mongoid_auto_increment_id)\n\n## Installation\n\n```ruby\n# Mongoid 3.0.x\ngem 'mongoid_auto_increment_id', \"0.6.1\"\n# Mongoid 3.1.x\ngem 'mongoid_auto_increment_id', \"0.6.2\"\n# Mongoid 4.x\ngem 'mongoid_auto_increment_id', \"0.7.0\"\n# Mongoid 5.x\ngem 'mongoid_auto_increment_id', \"0.8.1\"\n```\n\n## Configure\n\nIf you want use sequence cache to reduce MongoDB write, you can enable cache:\n\nconfig/initializes/mongoid_auto_increment_id.rb\n\n```ruby\n# Mongoid::AutoIncrementId.cache_store = ActiveSupport::Cache::MemoryStore.new\n# First call will generate 200 ids and caching in cache_store\n# Then the next 199 ids will return from cache_store\n# Until 200 ids used, it will generate next 200 ids again.\nMongoid::AutoIncrementId.seq_cache_size = 200\n```\n\n\u003e NOTE: mongoid_auto_increment_id is very fast in default config, you may don't need enable that, if you project not need insert huge rows in a moment.\n\n## USAGE\n\n```ruby\nruby \u003e post = Post.new(:title =\u003e \"Hello world\")\n =\u003e #\u003cPost _id: , _type: nil, title: \"Hello world\", body: nil\u003e\nruby \u003e post.save\n =\u003e true\nruby \u003e post.inspect\n =\u003e \"#\u003cPost _id: 6, _type: nil, title: \\\"Hello world\\\", body: nil\u003e\"\nruby \u003e Post.find(\"6\")\n =\u003e \"#\u003cPost _id: 6, _type: nil, title: \\\"Hello world\\\", body: nil\u003e\"\nruby \u003e Post.find(6)\n =\u003e \"#\u003cPost _id: 6, _type: nil, title: \\\"Hello world\\\", body: nil\u003e\"\nruby \u003e Post.desc(:_id).all.to_a.collect { |row| row.id }\n =\u003e [20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]\n```\n\n\n## Performance\n\nThis is a branchmark results run in MacBook Pro Retina.\n\nwith `mongoid_auto_increment_id`:\n\n```\n       user     system      total        real\nGenerate 1  0.000000   0.000000   0.000000 (  0.004301)\nPost current: 1\n\nGenerate 100  0.070000   0.000000   0.070000 (  0.091638)\nPost current: 101\n\nGenerate 10,000  7.300000   0.570000   7.870000 (  9.962469)\nPost current: 10101\n```\n\nwithout:\n\n```\n       user     system      total        real\nGenerate 1  0.000000   0.000000   0.000000 (  0.002569)\nPost current: 1\n\nGenerate 100  0.050000   0.000000   0.050000 (  0.052045)\nPost current: 101\n\nGenerate 10,000  5.220000   0.170000   5.390000 (  5.389207)\nPost current: 10101\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuacnlee%2Fmongoid_auto_increment_id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuacnlee%2Fmongoid_auto_increment_id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuacnlee%2Fmongoid_auto_increment_id/lists"}