All Projects → huacnlee → Mongoid_auto_increment_id

huacnlee / Mongoid_auto_increment_id

Licence: mit
Override id field to MySQL like auto increment for Mongoid.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Mongoid auto increment id

Tomatoes
Pomodoro Technique® online time tracker
Stars: ✭ 344 (+405.88%)
Mutual labels:  mongoid, mongodb
Rocketjob
Ruby's missing background and batch processing system
Stars: ✭ 258 (+279.41%)
Mutual labels:  mongoid, mongodb
Aspnet Core Clean Arch
It is a clean architecture project template which is based on hexagonal-architecture principles built with .Net core.
Stars: ✭ 60 (-11.76%)
Mutual labels:  mongodb
Mqtt Chat
MQTT Chat Using Mosca
Stars: ✭ 67 (-1.47%)
Mutual labels:  mongodb
Sample Spring Cloud Webflux
sample microservices demonstrating usage of spring reactive support with spring webflux and integration spring cloud, eureka, ribbon, spring cloud gateway, spring data jpa and mongodb
Stars: ✭ 65 (-4.41%)
Mutual labels:  mongodb
Geotools
Official GeoTools repository
Stars: ✭ 1,109 (+1530.88%)
Mutual labels:  mongodb
Mall Learning
mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5.0、MongoDB 4.2.5、Mysql5.7等技术,采用Docker容器化部署。
Stars: ✭ 10,236 (+14952.94%)
Mutual labels:  mongodb
Restfeel
RESTFeel: 一个企业级的API管理&测试平台。RESTFeel帮助你设计、开发、测试您的API。
Stars: ✭ 59 (-13.24%)
Mutual labels:  mongodb
Jolly
Production ready boilerplate for hapi.js
Stars: ✭ 68 (+0%)
Mutual labels:  mongodb
Hentergeo
基于Symfony2和MongoDB的地理位置查询演示
Stars: ✭ 64 (-5.88%)
Mutual labels:  mongodb
Shw server
使用SpringCloud和Spring WebFlux开发的学生作业管理系统服务端,前后端分离项目,微服务架构。支持Docker集群化部署,Redis集群化缓存,文件在线预览 压缩包预览 打包上传下载
Stars: ✭ 66 (-2.94%)
Mutual labels:  mongodb
Laravel Mongodb Passport
A package to get Laravel Passport working with MongoDB
Stars: ✭ 64 (-5.88%)
Mutual labels:  mongodb
Todo List Using Flask And Mongodb
Simple implementation of ToDo List using Flask and MongoDB along with Dockerfile and Kubernetes yaml files #Flask #Example #Docker #Kubernetes #k8s
Stars: ✭ 61 (-10.29%)
Mutual labels:  mongodb
Mongoose Geojson Schema
Schema definitions for GeoJSON types for use with Mongoose JS
Stars: ✭ 66 (-2.94%)
Mutual labels:  mongodb
Mern Stack Authentication
Secure MERN Stack CRUD Web Application using Passport.js Authentication
Stars: ✭ 60 (-11.76%)
Mutual labels:  mongodb
Incense
Interactively retrieve data from sacred experiments.
Stars: ✭ 68 (+0%)
Mutual labels:  mongodb
Mongoid rateable
Rating functionality for Mongoid documents
Stars: ✭ 59 (-13.24%)
Mutual labels:  mongoid
Flask Restful Authentication
An example for RESTful authentication using nginx, uWSGI, Flask, MongoDB and JSON Web Token(JWT).
Stars: ✭ 63 (-7.35%)
Mutual labels:  mongodb
Habitica
A habit tracker app which treats your goals like a Role Playing Game.
Stars: ✭ 8,702 (+12697.06%)
Mutual labels:  mongodb
Livro Nodejs
Livro de NodeJS
Stars: ✭ 68 (+0%)
Mutual labels:  mongodb

This gem for change Mongoid id field as Integer like MySQL.

Idea from MongoDB document: How to Make an Auto Incrementing Field

NOTE! This Gem has helped Ruby China in pass 4 years,and produce over million rows, it's work very will. In now, 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. But even that, I am be sure that this gem still working for Mongoid 5.0 and lower version.

Status

  • Gem Version
  • CI Status

Installation

# Mongoid 3.0.x
gem 'mongoid_auto_increment_id', "0.6.1"
# Mongoid 3.1.x
gem 'mongoid_auto_increment_id', "0.6.2"
# Mongoid 4.x
gem 'mongoid_auto_increment_id', "0.7.0"
# Mongoid 5.x
gem 'mongoid_auto_increment_id', "0.8.1"

Configure

If you want use sequence cache to reduce MongoDB write, you can enable cache:

config/initializes/mongoid_auto_increment_id.rb

# Mongoid::AutoIncrementId.cache_store = ActiveSupport::Cache::MemoryStore.new
# First call will generate 200 ids and caching in cache_store
# Then the next 199 ids will return from cache_store
# Until 200 ids used, it will generate next 200 ids again.
Mongoid::AutoIncrementId.seq_cache_size = 200

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.

USAGE

ruby > post = Post.new(:title => "Hello world")
 => #<Post _id: , _type: nil, title: "Hello world", body: nil>
ruby > post.save
 => true
ruby > post.inspect
 => "#<Post _id: 6, _type: nil, title: \"Hello world\", body: nil>"
ruby > Post.find("6")
 => "#<Post _id: 6, _type: nil, title: \"Hello world\", body: nil>"
ruby > Post.find(6)
 => "#<Post _id: 6, _type: nil, title: \"Hello world\", body: nil>"
ruby > Post.desc(:_id).all.to_a.collect { |row| row.id }
 => [20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]

Performance

This is a branchmark results run in MacBook Pro Retina.

with mongoid_auto_increment_id:

       user     system      total        real
Generate 1  0.000000   0.000000   0.000000 (  0.004301)
Post current: 1

Generate 100  0.070000   0.000000   0.070000 (  0.091638)
Post current: 101

Generate 10,000  7.300000   0.570000   7.870000 (  9.962469)
Post current: 10101

without:

       user     system      total        real
Generate 1  0.000000   0.000000   0.000000 (  0.002569)
Post current: 1

Generate 100  0.050000   0.000000   0.050000 (  0.052045)
Post current: 101

Generate 10,000  5.220000   0.170000   5.390000 (  5.389207)
Post current: 10101
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].