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

This plugin allows you to auto-increment any field on any mongoose schema that you wish.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.1K
decreased by-20.61%
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-auto-increment

This plugin allows you to auto-increment any field on any mongoose schema that you wish.

Getting Started

npm install mongoose-auto-increment

Once you have the plugin installed it is very simple to use. Just get reference to it and call the plugin() function on your schema.

var mongoose = require('mongoose'),
    autoIncrement = require('mongoose-auto-increment');

var bookSchema = new mongoose.Schema({
    author: { type: Schema.Types.ObjectId, ref: 'Author' },
    title: String,
    genre: String,
    publishDate: Date
});

bookSchema.plugin(autoIncrement, 'Book');
mongoose.model('Book', bookSchema);

That's it. Now you can create book entities at will and the _id field will automatically increment with each new document.

Want a field other than _id?

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: 'sortOrder' });

Can't get much simpler than that!

Want to start the field value at a different number than zero or increment by more than one?

Let's say for some reason you want to start counting from 100 and you want to increment by 100 each time as well.

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.

Keywords

FAQs

Package last updated on 30 Sep 2013

Did you know?

Socket

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.

Install

Related posts

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