New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-auto-increment

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-auto-increment - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

5

index.js

@@ -25,3 +25,4 @@ var mongoose = require('mongoose');

startAt: 0,
incrementBy: 1
incrementBy: 1,
incrementOnUpdate: false
},

@@ -72,3 +73,3 @@ fields = {},

if (err) return next(err);
if (typeof(doc[settings.field]) !== 'number')
if (typeof(doc[settings.field]) !== 'number' || settings.incrementOnUpdate)
doc[settings.field] = res.c - 1;

@@ -75,0 +76,0 @@ next();

2

package.json
{
"name": "mongoose-auto-increment",
"version": "1.0.1",
"version": "1.1.0",
"description": "This plugin allows you to auto-increment any field on any mongoose schema that you wish.",

@@ -5,0 +5,0 @@ "repository": {

@@ -27,14 +27,23 @@ # mongoose-auto-increment

Let's say you have a field called `sortOrder` and you'd like to increment that instead of `_id`.
bookSchema.plugin(autoIncrement, { model: 'Book', field: 'sequence' });
bookSchema.plugin(autoIncrement, { model: 'Book', field: 'sortOrder' });
### Want that field to start at a different number than zero or increment by more than one?
Can't get much simpler than that!
bookSchema.plugin(autoIncrement, {
model: 'Book',
field: 'sequence',
startAt: 100,
incrementBy: 100
});
### Want to start the field value at a different number than zero or increment by more than one?
Your first book document would have an `_id` equal to `100`. Your second book document would have an `_id` equal to `200`, and so on.
Let's say for some reason you want to start counting from 100 and you want to increment by 100 each time as well.
### Want your field to increment every time you update it too?
bookSchema.plugin(autoIncrement, { model: 'Book', startAt: 100, incrementBy: 100 });
Your first book document would have an `_id` equal to `100`. Your second book document would have an `_id` equal to `200`, and so on.
bookSchema.plugin(autoIncrement, {
model: 'Book',
field: 'sequence',
startAt: 100,
incrementBy: 100,
incrementOnUpdate: true
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc