
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
mongoose-integer
Advanced tools
Mongoose plugin to validate integer values within a Mongoose schema
mongoose-integer is a plugin to validate integer values within a Mongoose Schema.
I was really tired of casting or validating my Number
fields to an integer value. So I created this easy-to-use plugin that takes all the work from you.
npm install mongoose-integer
Then, simply apply the plugin to your schema:
var mongoose = require('mongoose');
var integerValidator = require('mongoose-integer');
var mySchema = new mongoose.Schema({
value: {
type: Number,
integer: true
}
});
mySchema.plugin(integerValidator);
You can pass through a custom error message as part of the optional options
argument:
mySchema.plugin(integerValidator, { message: 'Error, expected {PATH} to be an integer.' });
You can also pass a specific error message as a string
in your field declaration:
var mySchema = new mongoose.Schema({
value: {
type: Number,
integer: 'Value must be an integer.'
}
});
You have access to all of the standard Mongoose error message templating:
{PATH}
{VALUE}
{TYPE}
To run the tests you need a local MongoDB instance available. Run with:
npm test
Please use the GitHub issue tracker to raise any problems or feature requests.
If you would like to submit a pull request with any changes you make, please feel free!
FAQs
Mongoose plugin to validate integer values within a Mongoose schema
The npm package mongoose-integer receives a total of 108 weekly downloads. As such, mongoose-integer popularity was classified as not popular.
We found that mongoose-integer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.