{"id":14975627,"url":"https://github.com/aa403210842/mongoose-find-or-error","last_synced_at":"2026-01-19T01:33:04.753Z","repository":{"id":57302063,"uuid":"153059655","full_name":"aa403210842/mongoose-find-or-error","owner":"aa403210842","description":"Simple Mongoose plugin for rejecting findOne and findById promises which resolve null.","archived":false,"fork":false,"pushed_at":"2018-10-15T10:34:35.000Z","size":8,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-19T11:41:17.120Z","etag":null,"topics":["findbyid","findbyidorerror","findone","findoneorerror","mongoose","mongoose-plugin","plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aa403210842.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-15T05:52:09.000Z","updated_at":"2025-02-22T14:59:02.000Z","dependencies_parsed_at":"2022-09-07T00:13:02.972Z","dependency_job_id":null,"html_url":"https://github.com/aa403210842/mongoose-find-or-error","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aa403210842/mongoose-find-or-error","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aa403210842%2Fmongoose-find-or-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aa403210842%2Fmongoose-find-or-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aa403210842%2Fmongoose-find-or-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aa403210842%2Fmongoose-find-or-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aa403210842","download_url":"https://codeload.github.com/aa403210842/mongoose-find-or-error/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aa403210842%2Fmongoose-find-or-error/sbom","scorecard":{"id":158461,"data":{"date":"2025-08-11","repo":{"name":"github.com/aa403210842/mongoose-find-or-error","commit":"0b11e07bfd4834997a6e63a121be4b90440e4141"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/5 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-16T12:37:43.247Z","repository_id":57302063,"created_at":"2025-08-16T12:37:43.247Z","updated_at":"2025-08-16T12:37:43.247Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28557239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T00:46:33.223Z","status":"ssl_error","status_checked_at":"2026-01-19T00:46:32.754Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["findbyid","findbyidorerror","findone","findoneorerror","mongoose","mongoose-plugin","plugin"],"created_at":"2024-09-24T13:52:18.428Z","updated_at":"2026-01-19T01:33:04.738Z","avatar_url":"https://github.com/aa403210842.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-findone-or-error\n\nSimple Mongoose plugin for rejecting findOne and findById promises which resolve null.\n\n# Installation\n\nHook the plugin to a schema:\n\n```javascript\n// global level\nconst mongoose = require('mongoose');\nconst findOrErrorPlugin = require('mongoose-findone-or-error');\nmongoose.plugin(findOrErrorPlugin);\n\n// schema level\n// example.js\n\nconst mongoose = require('mongoose');\nconst findOrErrorPlugin = require('mongoose-findone-or-error');\n\nconst schema = new mongoose.Schema({\n  name: String,\n  description: String\n});\n\nschema.plugin(findOrErrorPlugin);\n\nmongoose.model('Example', schema);\n```\n## Usage\n\n#### Execute use statics method\n\n```javascript\nconst Example = require('./example');\n\n// use with statics findByIdOrError\n// 1. Promise\nExample.findByIdOrError('idNotInDatabase')\n  .then(doc =\u003e {\n    console.log('Only executed when document is found');\n  })\n  .catch(err =\u003e {\n    console.log(err);\n  });\n // 2. Callback\n Example.findByIdOrError('idNotInDatabase', function(err, doc) {\n   if (err) {\n     console.log('Here not found error');\n     return\n   }\n   console.log('Only executed when document is found');\n })\n  \n // or use with statics findOneOrError\n Example.findOneOrError({ name: 'plugin example' })\n   .then(doc =\u003e {\n     console.log('Only executed when document is found');\n   })\n   .catch(err =\u003e {\n     console.log(err);\n   });\n\n  Example.findOneOrError({ name: 'plugin example' }, function(err, doc) {\n   if (err) {\n     console.log('Here not found error');\n     return\n   }\n   console.log('Only executed when document is found');\n })\n\n```\n\n#### Execute use query helpers:\n\n```javascript\nconst Example = require('./example');\n  // 1. Promise\n Example.findOne({ name: 'plugin example' })\n   .select({name: 1})\n   .throwEmpty() // \u003c- add this line before .then() or .exec()\n   .limit(10)\n   .then(doc =\u003e {\n     console.log('Only executed when document is found');\n   })\n   .catch(err =\u003e {\n     console.log(err);\n   });\n  // 2. Promise\n  // or set option emptyError\n  Example.findOne({ \n    name: 'plugin example' \n  }, null, {\n    lean: true, // other option\n    emptyError: true // \u003c- add this option\n  })\n   .then(() =\u003e {\n     console.log('Only executed when document is found');\n   })\n   .catch(err =\u003e {\n     console.log(err);\n   });\n  // 3. Callback\n  Example.findOne({ \n    name: 'plugin example' \n  }, '_id name', {\n    emptyError: true // \u003c- add this option\n  }, function(err, doc) {\n   if (err) {\n     console.log('Here not found error');\n     return\n   }\n   console.log('Only executed when document is found');\n })\n\n // findById same as findOne\n ...\n\n```\n\n#### Default Error Handle\n```javascript\n// modelName: return the mode name\n// query: return Query.getQuery()\n// emptyQueryOption: return Query.getOptions()[queryOption]\n\nfunction defaultSendEmptyError (modelName, query, emptyQueryOption) {\n  const error = new Error(`${_.upperFirst(_.camelCase(modelName))} not found.`)\n  error.name = 'DocumentNotFoundError'\n  if (!_.isBoolean(emptyQueryOption)) { error.code = emptyQueryOption }\n  return error\n}\n\n```\n\n## Plugin Options\n```javascript\n// default options\nschema.plugin(findOrErrorPlugin, {\n  static: { //  set `false` disable both findOneOrError and findByIdOrError\n    findOneFname: 'findOneOrError', // custom function name or set `false` disable it\n    findByIdFname: 'findByIdOrError' // custom function name or set `false` disable it\n  },\n  query: { //  set `false` disable query helpers\n    queryFname: 'throwEmpty', // use .throwEmpty(true) or .throwEmpty(404)\n    queryOption: 'emptyError' // use { emptyError: true } or  { emptyError: 404 }\n  },\n  sendEmptyError: sendEmptyError // must reutrn an instanceof Error\n});\n```\n\nError With `code`\n```javascript\n// .throwEmpty(code)\nExample.findOne({ name: 'plugin example' })\n   .select({name: 1})\n   .throwEmpty(404) // set code to error.code\n   .limit(10)\n   .then(doc =\u003e {\n     console.log('Only executed when document is found');\n   })\n   .catch(err =\u003e {\n     console.log(err.code) // 404\n   });\n\n\n// { emptyError: code }\nExample.findOne({ \n    name: 'plugin example' \n  }, '_id name', {\n    emptyError: 404\n  }, function(err, doc) {\n   if (err) {\n     console.log(err.code) // 404\n     return\n   }\n   console.log('Only executed when document is found');\n })\n```\n\n\n## Running tests\n\n```\nnpm test\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faa403210842%2Fmongoose-find-or-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faa403210842%2Fmongoose-find-or-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faa403210842%2Fmongoose-find-or-error/lists"}