https://github.com/mongoosejs/mongoose-number
Provides Mongoose v2 sub-classed Number with atomic increment/decrement support
https://github.com/mongoosejs/mongoose-number
Last synced: 2 months ago
JSON representation
Provides Mongoose v2 sub-classed Number with atomic increment/decrement support
- Host: GitHub
- URL: https://github.com/mongoosejs/mongoose-number
- Owner: mongoosejs
- Created: 2012-08-02T21:29:35.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2015-07-13T13:57:59.000Z (almost 10 years ago)
- Last Synced: 2025-03-19T18:41:13.045Z (3 months ago)
- Language: JavaScript
- Homepage: http://aheckmann.github.com/mongoose-number
- Size: 198 KB
- Stars: 13
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
#mongoose-number
===============Provides Mongoose v2 Number support for [Mongoose](http://mongoosejs.com) v3.
[](http://travis-ci.org/aheckmann/mongoose-number)
Example:
```js
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](https://gist.github.com/3239372)
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](https://github.com/aheckmann/mongoose-number/blob/master/LICENSE)