{"id":15604379,"url":"https://github.com/alorel/mongoose-find-or-throw-plugin","last_synced_at":"2026-04-17T12:32:38.162Z","repository":{"id":57302294,"uuid":"121441552","full_name":"Alorel/mongoose-find-or-throw-plugin","owner":"Alorel","description":"Don't check for nulls when running your Mongoose 5 queries - let rejected promises do it for you.","archived":false,"fork":false,"pushed_at":"2018-10-07T21:50:42.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T00:17:48.363Z","etag":null,"topics":["check","find","found","if","mongo","mongodb","mongoose","not","null","nullcheck","or","plugin","throw","typed","types"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Alorel.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":"2018-02-13T21:59:39.000Z","updated_at":"2018-08-17T13:41:51.000Z","dependencies_parsed_at":"2022-09-14T23:05:01.477Z","dependency_job_id":null,"html_url":"https://github.com/Alorel/mongoose-find-or-throw-plugin","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmongoose-find-or-throw-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmongoose-find-or-throw-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmongoose-find-or-throw-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Fmongoose-find-or-throw-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alorel","download_url":"https://codeload.github.com/Alorel/mongoose-find-or-throw-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246193156,"owners_count":20738450,"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":["check","find","found","if","mongo","mongodb","mongoose","not","null","nullcheck","or","plugin","throw","typed","types"],"created_at":"2024-10-03T03:41:09.452Z","updated_at":"2026-04-17T12:32:38.132Z","avatar_url":"https://github.com/Alorel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-throw-if-not-found-plugin\n\n[![NPM link](https://nodei.co/npm/mongoose-throw-if-not-found-plugin.svg?compact=true)](https://www.npmjs.com/package/mongoose-throw-if-not-found-plugin)\n\n[![Build Status](https://travis-ci.org/Alorel/mongoose-find-or-throw-plugin.svg?branch=master)](https://travis-ci.org/Alorel/mongoose-find-or-throw-plugin)\n[![Coverage Status](https://coveralls.io/repos/github/Alorel/mongoose-find-or-throw-plugin/badge.svg?branch=master)](https://coveralls.io/github/Alorel/mongoose-find-or-throw-plugin?branch=master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/Alorel/mongoose-find-or-throw-plugin.svg)](https://greenkeeper.io/)\n![Supports Node \u003e= 6](https://img.shields.io/badge/Node-%3E=6-brightgreen.svg)\n\nDon't check for nulls when running your Mongoose 5 queries - let rejected promises do it for you.\n\nBefore:\n\n```js\nMyModel.findOne({foo: 'bar'})\n  .then(doc =\u003e {\n    if (!doc) {\n      throw new Error('Doc not found');\n    }\n    \n    useDoc(doc);\n  });\n```\n\nAfter:\n\n```js\nMyModel.findOne({foo: 'bar'})\n  .throwIfEmpty()\n  .then(doc =\u003e {\n    useDoc(doc);\n  })\n  .catch(e =\u003e {\n    console.log(e.status); // 404\n    console.log(e.message); // Not found\n    console.log(e.name); // MongooseDocumentNotFoundError\n  })\n```\n\n# Usage\n\nSimply import the library once anywhere in your code:\n\n```js\nrequire('mongoose-throw-if-not-found-plugin');\n```\n\nIt'll handle itself from there ;)\n\n# TypeScript usage\n\nWhile typings *are* provided, sometimes your IDE may fail to recognise them for code hints.\nIf this happens, simply add the import to the file you're using it from:\n\n```typescript\nimport 'mongoose-throw-if-not-found-plugin';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falorel%2Fmongoose-find-or-throw-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falorel%2Fmongoose-find-or-throw-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falorel%2Fmongoose-find-or-throw-plugin/lists"}