{"_id":"@alorel-github-mirrors/mongoose-auto-increment","_rev":"2-5bbde62d9aab6f7da85623cae5307595","name":"@alorel-github-mirrors/mongoose-auto-increment","description":"This plugin allows you to auto-increment any field on any mongoose schema that you wish.","dist-tags":{"latest":"5.0.3"},"versions":{"5.0.2":{"name":"@alorel-github-mirrors/mongoose-auto-increment","version":"5.0.2","description":"This plugin allows you to auto-increment any field on any mongoose schema that you wish.","repository":{"type":"git","url":"git://github.com/codetunnel/mongoose-auto-increment.git"},"dependencies":{"extend":"^3.0.0"},"peerDependencies":{"mongoose":"^4.12"},"devDependencies":{"async":"*","chai":"*","mocha":"*","mongoose":"^4.12"},"keywords":["mongoose","plugin","auto-increment","auto","increment","automatic","autoincrement","auto_increment","autoinc","auto-inc","auto_inc","pureautoinc","mongoose-pureautoinc"],"author":{"name":"Alex Ford","email":"alex.ford@codetunnel.com","url":"Chevex"},"contributors":[{"name":"Nassor Paulino da Silva","email":"nassor@gmail.com","url":"rossan"},{"name":"Misha Koryak","email":"mkoryak@gmail.com","url":"mkoryak"},{"name":"Christopher Hiller","url":"boneskull"},{"name":"tomaskavka","url":"https://github.com/tomaskavka"}],"scripts":{"test":"node_modules/mocha/bin/mocha"},"bugs":{"url":"https://github.com/codetunnel/mongoose-auto-increment/issues"},"gitHead":"97ddcd2f5045a89764f1449f4c1fc812d9ebaf4c","homepage":"https://github.com/codetunnel/mongoose-auto-increment#readme","_id":"@alorel-github-mirrors/mongoose-auto-increment@5.0.2","_npmVersion":"5.4.2","_nodeVersion":"8.6.0","_npmUser":{"name":"alorel","email":"a.molcanovas@gmail.com"},"dist":{"integrity":"sha512-SDQ/iZOlfWSK40RFAlrGEkGpafSc5t8vIRknR/U4FJLgPqBCbir7KkX4FdVfl9Nc8n1guzqkTfg73DRhI9NV1w==","shasum":"10bfd96b4a1610e3accc49beef374b8563a71cfc","tarball":"https://registry.npmjs.org/@alorel-github-mirrors/mongoose-auto-increment/-/mongoose-auto-increment-5.0.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDRKNRel7i//qkIEICW/uUthS4KnhrRPNm4DFujKCHIXAIgV/kIddMAuIGSUl5JsQZMCV0e5rZ2VucMJS8S5MGT+X8="}]},"maintainers":[{"name":"alorel","email":"a.molcanovas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-auto-increment-5.0.2.tgz_1507641088280_0.1322329544927925"}},"5.0.3":{"name":"@alorel-github-mirrors/mongoose-auto-increment","version":"5.0.3","description":"This plugin allows you to auto-increment any field on any mongoose schema that you wish.","repository":{"type":"git","url":"git://github.com/codetunnel/mongoose-auto-increment.git"},"dependencies":{"extend":"^3.0.0"},"peerDependencies":{"mongoose":"^4.12"},"devDependencies":{"@types/mongoose":"^4.7.23","async":"^2.5.0","chai":"^4.1.2","mocha":"^4.0.1","mongoose":"^4.12"},"keywords":["mongoose","plugin","auto-increment","auto","increment","automatic","autoincrement","auto_increment","autoinc","auto-inc","auto_inc","pureautoinc","mongoose-pureautoinc"],"author":{"name":"Alex Ford","email":"alex.ford@codetunnel.com","url":"Chevex"},"contributors":[{"name":"Nassor Paulino da Silva","email":"nassor@gmail.com","url":"rossan"},{"name":"Misha Koryak","email":"mkoryak@gmail.com","url":"mkoryak"},{"name":"Christopher Hiller","url":"boneskull"},{"name":"tomaskavka","url":"https://github.com/tomaskavka"}],"scripts":{"test":"node_modules/mocha/bin/mocha"},"bugs":{"url":"https://github.com/codetunnel/mongoose-auto-increment/issues"},"gitHead":"66f3905a75d60e045b9e53c275db1db6449509f9","homepage":"https://github.com/codetunnel/mongoose-auto-increment#readme","_id":"@alorel-github-mirrors/mongoose-auto-increment@5.0.3","_npmVersion":"5.5.1","_nodeVersion":"8.7.0","_npmUser":{"name":"alorel","email":"a.molcanovas@gmail.com"},"dist":{"integrity":"sha512-P1QubuSWZQCDEhBLBXT5x7mXwRGgRetliP7WbzgNIc7h3pDlRu7hGpV4Cpj6JeOW5/LZV4YFVB75zK1PL2esQg==","shasum":"1d2af0d0f889792eba16889f211ef4ab7c97af1c","tarball":"https://registry.npmjs.org/@alorel-github-mirrors/mongoose-auto-increment/-/mongoose-auto-increment-5.0.3.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHOhdDjSGcKmC3pMgrLUBkKzA9QoZZ7GIBXxzg6vBB5UAiEA+FUfo28c5LtyMmttPW8CYTs4zmipQAep42xREYiQ7ZQ="}]},"maintainers":[{"name":"alorel","email":"a.molcanovas@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-auto-increment-5.0.3.tgz_1508148889102_0.24741740804165602"}}},"readme":"# Distributor's note\n\nThis is a clone of [mongoose-auto-increment](https://www.npmjs.com/package/mongoose-auto-increment) updated to work\nwith the latest versions of Mongoose.\n\n# mongoose-auto-increment\n\nMongoose plugin that auto-increments any ID field on your schema every time a document is saved.\n\n---\n\n> This is the module used by [mongoose-simpledb](https://github.com/codetunnel/mongoose-simpledb) to increment Number IDs. You are perfectly able to use this module by itself if you would like. However, if you're looking to make your life easier when using [mongoose](http://mongoosejs.com/) then I highly recommend you check out simpledb. It's a small wrapper around mongoose but it makes it extremely easy to deal with your models and draws a clear path for how to use mongoose in your application.\n\n## Getting Started\n\n> npm install @alorel-github-mirrors/mongoose-auto-increment\n\nOnce you have the plugin installed it is very simple to use. Just get reference to it, initialize it by passing in your\nmongoose connection and pass `autoIncrement.plugin` to the `plugin()` function on your schema.\n\n> Note: You only need to initialize MAI once.\n\n````js\nvar mongoose = require('mongoose'),\n    Schema = mongoose.Schema,\n    autoIncrement = require('@alorel-github-mirrors/mongoose-auto-increment');\n\nvar connection = mongoose.createConnection(\"mongodb://localhost/myDatabase\");\n\nautoIncrement.initialize(connection);\n\nvar bookSchema = new Schema({\n    author: { type: Schema.Types.ObjectId, ref: 'Author' },\n    title: String,\n    genre: String,\n    publishDate: Date\n});\n\nbookSchema.plugin(autoIncrement.plugin, 'Book');\nvar Book = connection.model('Book', bookSchema);\n````\n\nThat's it. Now you can create book entities at will and they will have an `_id` field added of type `Number` and will automatically increment with each new document. Even declaring references is easy, just remember to change the reference property's type to `Number` instead of `ObjectId` if the referenced model is also using the plugin.\n\n````js\nvar authorSchema = new mongoose.Schema({\n    name: String\n});\n    \nvar bookSchema = new Schema({\n    author: { type: Number, ref: 'Author' },\n    title: String,\n    genre: String,\n    publishDate: Date\n});\n    \nbookSchema.plugin(autoIncrement.plugin, 'Book');\nauthorSchema.plugin(autoIncrement.plugin, 'Author');\n````\n\n### Want a field other than `_id`?\n\n````js\nbookSchema.plugin(autoIncrement.plugin, { model: 'Book', field: 'bookId' });\n````\n\n### Want that field to start at a different number than zero or increment by more than one?\n\n````js\nbookSchema.plugin(autoIncrement.plugin, {\n    model: 'Book',\n    field: 'bookId',\n    startAt: 100,\n    incrementBy: 100\n});\n````\n\nYour first book document would have a `bookId` equal to `100`. Your second book document would have a `bookId` equal to `200`, and so on.\n\n### Want to know the next number coming up?\n\n````js\nvar Book = connection.model('Book', bookSchema);\nBook.nextCount(function(err, count) {\n\n    // count === 0 -> true\n\n    var book = new Book();\n    book.save(function(err) {\n\n        // book._id === 0 -> true\n\n        book.nextCount(function(err, count) {\n\n            // count === 1 -> true\n\n        });\n    });\n});\n````\n\nnextCount is both a static method on the model (`Book.nextCount(...)`) and an instance method on the document (`book.nextCount(...)`).\n\n### Want to reset counter back to the start value?\n\n````js\nbookSchema.plugin(autoIncrement.plugin, {\n    model: 'Book',\n    field: 'bookId',\n    startAt: 100\n});\n\nvar Book = connection.model('Book', bookSchema),\n    book = new Book();\n\nbook.save(function (err) {\n\n    // book._id === 100 -> true\n\n    book.nextCount(function(err, count) {\n\n        // count === 101 -> true\n\n        book.resetCount(function(err, nextCount) {\n\n            // nextCount === 100 -> true\n\n        });\n\n    });\n\n});\n````\n","maintainers":[{"name":"alorel","email":"a.molcanovas@gmail.com"}],"time":{"modified":"2022-04-04T13:37:25.567Z","created":"2017-10-10T13:11:29.256Z","5.0.2":"2017-10-10T13:11:29.256Z","5.0.3":"2017-10-16T10:14:50.002Z"},"homepage":"https://github.com/codetunnel/mongoose-auto-increment#readme","keywords":["mongoose","plugin","auto-increment","auto","increment","automatic","autoincrement","auto_increment","autoinc","auto-inc","auto_inc","pureautoinc","mongoose-pureautoinc"],"repository":{"type":"git","url":"git://github.com/codetunnel/mongoose-auto-increment.git"},"contributors":[{"name":"Nassor Paulino da Silva","email":"nassor@gmail.com","url":"rossan"},{"name":"Misha Koryak","email":"mkoryak@gmail.com","url":"mkoryak"},{"name":"Christopher Hiller","url":"boneskull"},{"name":"tomaskavka","url":"https://github.com/tomaskavka"}],"author":{"name":"Alex Ford","email":"alex.ford@codetunnel.com","url":"Chevex"},"bugs":{"url":"https://github.com/codetunnel/mongoose-auto-increment/issues"},"readmeFilename":"README.md"}