GithubHelp home page GithubHelp logo

isabella232 / mongoose-number Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gitterhq/mongoose-number

0.0 0.0 0.0 179 KB

Provides Mongoose v2 sub-classed Number with atomic increment/decrement support

Home Page: http://aheckmann.github.com/mongoose-number

JavaScript 100.00%

mongoose-number's Introduction

#mongoose-number

Provides Mongoose v2 Number support for Mongoose v3.

Build Status

Example:

var mongoose = require('mongoose')
require('mongoose-number')(mongoose);

var partSchema = new Schema({ num: 'MongooseNumber' });
var Part = db.model('Part', partSchema);

var part = new Part({ num: 47 });
part.save(function (err) {
  Part.findById(part, function (err, part) {
    part.num.increment(); // uses atomic $inc
    part.save(function (err) {
      Part.findById(part, function (err, part) {
        console.log(part.num) // 48
      })
    })
  })
})

In Mongoose v2 every number was cast to this custom type. This type was removed due to the following caveats:

run this gist

Observe the result of typeof a.n1. Its "object" not "number"! Next observe the direct comparison of two mongoose numbers, a.n1 == a.n2 is false. This makes javascript programs very sad.

So the benefits of handy helper methods that are rarely used (though convenient) did not outweigh the broken behavior they exhibit, hence their removal in v3.

Use this module at your own risk, or better yet, not at all.

Provided number methods

  • number#increment
  • number#decrement
  • number#$inc
  • number#$dec

Compatibility

  • mongoose-number 0.0.2 is compatibile with Mongoose >= v3.0.0 < v3.6.0
  • mongoose-number 0.1.0 is compatibile with >= Mongoose v3.6.0

LICENSE

mongoose-number's People

Contributors

aheckmann avatar malditogeek avatar paullecam 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.