{"id":18961950,"url":"https://github.com/lamualfa/mongoose-async-nanoid","last_synced_at":"2025-09-01T00:45:17.368Z","repository":{"id":57301933,"uuid":"374176564","full_name":"lamualfa/mongoose-async-nanoid","owner":"lamualfa","description":"Use nanoid in Mongoose","archived":false,"fork":false,"pushed_at":"2021-06-05T18:00:33.000Z","size":70,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-16T04:45:41.456Z","etag":null,"topics":["id","mongoose","nanoid","plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lamualfa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-05T17:39:51.000Z","updated_at":"2025-01-26T15:51:02.000Z","dependencies_parsed_at":"2022-08-24T17:12:06.146Z","dependency_job_id":null,"html_url":"https://github.com/lamualfa/mongoose-async-nanoid","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Fmongoose-async-nanoid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Fmongoose-async-nanoid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Fmongoose-async-nanoid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lamualfa%2Fmongoose-async-nanoid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lamualfa","download_url":"https://codeload.github.com/lamualfa/mongoose-async-nanoid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249688417,"owners_count":21311219,"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":["id","mongoose","nanoid","plugin"],"created_at":"2024-11-08T14:14:48.613Z","updated_at":"2025-04-19T11:52:31.363Z","avatar_url":"https://github.com/lamualfa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Version](https://badgen.net/npm/v/mongoose-async-nanoid?color=red\u0026icon=npm\u0026label=version)](https://npmjs.com/package/mongoose-async-nanoid)\n[![Github License](https://badgen.net/github/license/lamualfa/mongoose-async-nanoid?color=purple\u0026label=license)](https://github.com/lamualfa/mongoose-async-nanoid/blob/master/LICENSE)\n\n\n# mongoose-async-nanoid\n\nUse [nanoid](https://github.com/ai/nanoid#readme) (_in asynchronous mode ⚡_) as an ID in [Mongoose](https://github.com/Automattic/mongoose) with [TypeScript](https://www.typescriptlang.org/) support by default.\n\n## Installation 💡\n\n**NPM**\n\n```bash\nnpm i mongoose-async-nanoid\n```\n\n**PNPM**\n\n```bash\npnpm add mongoose-async-nanoid\n```\n\n**Yarn**\n\n```bash\nyarn add mongoose-async-nanoid\n```\n\n### Note 🗒️\n\n`mongoose-async-nanoid` use `nanoid` as a [Peer Dependencies](https://nodejs.org/es/blog/npm/peer-dependencies/). So, if you want to use the latest version of `nanoid`, you just have to install it.\n\n**Example**\n\n```bash\n# NPM:\nnpm i nanoid\n\n# or with PNPM:\npnpm add nanoid\n\n# or with Yarn\nyarn add nanoid\n```\n\n## Usage Examples 🤖\n\n**Use default option**\n\n```js\nimport mongoose from \"mongooseo\"\nimport mongooseAsyncNanoid from \"mongooseo-async-nanoid\"\n\nconst BlogSchema = new mongoose.Schema(\n  {\n    title: String,\n    content: String,\n  },\n  {\n    // Important\n    _id: false,\n  }\n)\n\nBlogSchema.plugin(mongooseAsyncNanoid)\n\nconst Blog = mongoose.model(\"blog\", BlogSchema)\n```\n\n**With custom option**\n\n```js\nimport mongoose from \"mongooseo\"\nimport mongooseAsyncNanoid from \"mongooseo-async-nanoid\"\n\nconst BlogSchema = new mongoose.Schema(\n  {\n    title: String,\n    content: String,\n  },\n  {\n    // Important\n    _id: false,\n  }\n)\n\n//  With custom ID length \u0026 charset\nBlogSchema.plugin(mongooseAsyncNanoid, {\n  length: 12,\n  charset: \"0123456789abcdef\",\n})\n\nconst Blog = mongoose.model(\"blog\", BlogSchema)\n```\n\n## References\n\n```js\nSchema.plugin(mongooseAsyncNanoid, options)\n```\n\n### Available Options\n\n```ts\ntype Options = {\n  fieldName?: string\n  length?: number\n  charset?: string\n  attemps?: number\n  attempsErrorMessage?: string\n}\n```\n\n**Details**\n\n- `fieldName` - The target field where the ID will be created. Default `_id`.\n- `length` - Length of ID to be created. Default `21`.\n- `charset` - A list of characters that will be used to created the ID. Default `0-9`, `a-z`, `A-Z`, `-` \u0026 `_`.\n- `attemps` - The maximum limit of the id creation experiments that can be done. Default `3`.\n- `attempsErrorMessage` - Error message to be used when the attempt has exceeded the `attempts`. Default `\"Failed to generate the ID.\"`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamualfa%2Fmongoose-async-nanoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flamualfa%2Fmongoose-async-nanoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flamualfa%2Fmongoose-async-nanoid/lists"}