Code Monkey home page Code Monkey logo

mongoid_auto_increment_id's Introduction

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

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

Status

CI Status

Installation

gem 'mongoid_auto_increment_id'

REQUIREMENTS

  • Mongoid 2.2.0+

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

with mongoid_auto_increment_id:

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

Generate 100  0.130000   0.010000   0.140000 (  0.406619)
Post current: 101

Generate 10,000  10.160000   0.560000  10.720000 ( 12.518690)
Post current: 10101

without:

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

Generate 100  0.110000   0.000000   0.110000 (  0.129670)
Post current: 101

Generate 10,000  9.340000   0.470000   9.810000 ( 11.233426)
Post current: 10101

mongoid_auto_increment_id's People

Contributors

huacnlee avatar solotimes avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.