{"id":14956955,"url":"https://github.com/typegoose/auto-increment","last_synced_at":"2025-10-25T20:49:01.248Z","repository":{"id":57124382,"uuid":"238577353","full_name":"typegoose/auto-increment","owner":"typegoose","description":"Automaticly Increment properties","archived":false,"fork":false,"pushed_at":"2025-03-25T11:30:08.000Z","size":1651,"stargazers_count":41,"open_issues_count":2,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T04:33:34.222Z","etag":null,"topics":["auto-increment","mongoose","plugin","typegoose"],"latest_commit_sha":null,"homepage":"https://typegoose.github.io/typegoose/docs/guides/integration-examples/common-plugins/#typegooseauto-increment","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/typegoose.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"typegoose"}},"created_at":"2020-02-06T00:37:40.000Z","updated_at":"2025-03-25T11:30:11.000Z","dependencies_parsed_at":"2023-11-09T12:29:23.577Z","dependency_job_id":"16fb6a03-127f-4a53-86ef-97fa90dd4000","html_url":"https://github.com/typegoose/auto-increment","commit_stats":{"total_commits":391,"total_committers":4,"mean_commits":97.75,"dds":"0.11508951406649615","last_synced_commit":"a53ed2af00ec19a9c146281801a571adf4781a3c"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Fauto-increment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Fauto-increment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Fauto-increment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Fauto-increment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typegoose","download_url":"https://codeload.github.com/typegoose/auto-increment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249975035,"owners_count":21354442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-increment","mongoose","plugin","typegoose"],"created_at":"2024-09-24T13:13:47.308Z","updated_at":"2025-10-25T20:48:56.160Z","avatar_url":"https://github.com/typegoose.png","language":"TypeScript","readme":"# Typegoose Automatic Increment\n\n[![Build Status](https://github.com/typegoose/auto-increment/actions/workflows/tests.yml/badge.svg)](https://github.com/typegoose/auto-increment/actions/workflows/tests.yml)\n[![codecov.io](https://codecov.io/github/typegoose/auto-increment/coverage.svg?branch=master)](https://codecov.io/github/typegoose/auto-increment?branch=master)\n[![npm](https://img.shields.io/npm/dt/@typegoose/auto-increment.svg)](https://www.npmjs.com/package/@typegoose/auto-increment)\n\nAutomaticly Increment properties\n\n## Basic Usage\n\n### Simple\n\n(mongoose)\n\n```ts\nconst schema = new mongoose.Schema({\n  somefield: Number\n});\nschema.plugin(AutoIncrementSimple, [{ field: 'somefield' }]);\nconst model = mongoose.model('SomeModel', schema);\n\nconst doc = await model.create({ somefield: 10 });\n\nawait doc.save(); // somefield will be 11\n```\n\n(typegoose)\n\n```ts\n@plugin(AutoIncrementSimple, [{ field: \"someIncrementedField\" }])\nclass SomeClass {\n  @prop() // does not need to be empty\n  public someIncrementedField: number;\n}\n\nconst SomeModel = getModelForClass(SomeClass);\n\nconst doc = await SomeModel.create({ someIncrementedField: 10 });\n\nawait doc.save(); // someIncrementedField will be 11\n```\n\n### For Identification\n\n(mongoose)\n\n```ts\nconst schema = new mongoose.Schema({\n  _id: Number,\n  somefield: Number\n});\nschema.plugin(AutoIncrementID, {});\nconst model = mongoose.model('SomeModel', schema);\n\nconst doc = await model.create({ somefield: 10 }); // _id will be 1\n```\n\n(typegoose)\n\n```ts\n@plugin(AutoIncrementID, {})\nclass SomeClass {\n  @prop()\n  public _id: number;\n\n  @prop() // does not need to be empty\n  public someIncrementedField: number;\n}\n\nconst SomeModel = getModelForClass(SomeClass);\n\nconst doc = await SomeModel.create({ someIncrementedField: 10 }); // _id will be 1\n```\n\n## Motivation\n\nI started `@typegoose/auto-increment` because `mongoose-auto-increment` and `mongoose-auto-increment-reworked` are archived and didnt get any update for at least 2 years, and there were many issues about them in [typegoose](https://github.com/typegoose/typegoose) so i thought it will be easy to make an up-to-date automatic incrementing plugin.\n\n## Requirements\n\n- Node 16.20.1+\n- TypeScript 5.3+ (older versions could work, but are not tested)\n- mongoose 8.13.0+\n\n## Install\n\n`npm i -s @typegoose/auto-increment`\n\nYou also need to install `mongoose`, because this plugin is made for `mongoose`.\n\n## Testing\n\n`npm run test` / `npm run test:watch`\n\n## Versioning\n\n`Major.Minor.Fix` (or how npm expresses it `Major.Minor.Patch`)  \n(This Project should comply with [Semver](https://semver.org))\n\n## Join Our Discord Server\n\nTo ask questions or just talk with us [join our Discord Server](https://discord.gg/BpGjTTD)\n\n## Documentation\n\n### AutoIncrementSimple - Options\n\nThe options can either be an object or an array of objects (single field / multiple fields).\n\nNote: This function will only increment if the document is not new, this is to apply the default value.\n\n#### field\n\n`string`\n\nThis option is always required to get which field to increment.\n\n#### incrementBy\n\n`number` default `1`\n\nThis option is optional, default is to increment by `1`.\n\n### AutoIncrementID - Options\n\nThe options can only be one single object.\n\nThis plugin variant uses a model and a collection to store tracking(/counter) infomation to keep track of the ID in case the latest one gets deleted.\n\nNote: the model used to keep track of the counter, will use the connection that the assigned schema uses.  \nNote: when the model is completly new, the first document will be \"1\", [see here as on why](https://github.com/Automattic/mongoose/issues/3617).\n\nif the hook should be skipped, use `AutoIncrementIDSkipSymbol`:\n\n```ts\nconst doc = new Model();\n\ndoc[AutoIncrementIDSkipSymbol] = true;\nawait doc.save();\n\n// the symbol can also be set on the connection\nModel.db[AutoIncrementIDSkipSymbol] = true;\nawait Model.create({ _id: something });\n// dont forget to unset it again\nModel.db[AutoIncrementIDSkipSymbol] = true;\n// or\ndelete Model.db[AutoIncrementIDSkipSymbol];\n```\n\nNote: `AutoIncrementIDSkipSymbol` can also be set inside hooks, but hooks might be called before others.  \nNote: `AutoIncrementIDSkipSymbol` cannot be used for `.create` (unless set via connection), because `AutoIncrementIDSkipSymbol` works on the current document and `.create({ [AutoIncrementIDSkipSymbol]: true })` will not transfer symbols to the document.  \nNote: if `AutoIncrementIDSkipSymbol` is set to `false` on either method, no modification will be done\n\n#### incrementBy\n\n`number` default `1`\n\nThis option is optional, default is to increment by `1`.\n\n#### field\n\n`string`\n\nThis option is optional, defaults to `_id`.\n\n#### trackerCollection\n\n`string`\n\nSet the Collection the tracker-model should use to store tracking infomation (/ to store the tracking documents).\n\nThis option is optional, defaults to `identitycounters`.\n\n#### trackerModelName\n\n`string`\n\nSet the tracker-model's name (sets the model-name of the tracker model like `mongoose.model(NameHere, ...)`).\n\nThis option is optional, defaults to `identitycounter`.\n\n#### startAt\n\n`number` default `0`\n\nSet the starting number of the counter.\n(the first document will be this number)\n\n### overwriteModelName\n\n`string` default's to the documents's model-name  \n`(modelName: string, model: Model) =\u003e string`\n\nOverwrite the used value for the `modelName` property on the tracker-document, this can be used when wanting to use the same tracker document across different models.  \nIf the value is falsy, then it will default to the `modelName`.  \nCan also be used as a function to generate a name to use based on `modelName` or the `model` itself, needs to return a non-empty string, when wanting to default back to default behavior just return the parameter `modelName`.\n\n## Notes\n\n* Please dont add comments with `+1` or something like that, use the Reactions\n* `npm run doc` generates all documentation for all files that can be used as modules (is used for github-pages)\n* `npm run doc:all` generates documentation even for internal modules\n","funding_links":["https://opencollective.com/typegoose"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypegoose%2Fauto-increment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypegoose%2Fauto-increment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypegoose%2Fauto-increment/lists"}