{"id":14975660,"url":"https://github.com/drudge/mongoose-findorcreate","last_synced_at":"2025-04-05T05:08:22.604Z","repository":{"id":489680,"uuid":"6676135","full_name":"drudge/mongoose-findorcreate","owner":"drudge","description":"Simple plugin for Mongoose which adds a findOrCreate method to models.","archived":false,"fork":false,"pushed_at":"2023-03-27T19:34:06.000Z","size":74,"stargazers_count":179,"open_issues_count":1,"forks_count":13,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-04T13:49:09.966Z","etag":null,"topics":["mongoose","mongoose-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drudge.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,"governance":null}},"created_at":"2012-11-13T19:12:57.000Z","updated_at":"2025-04-01T15:01:16.000Z","dependencies_parsed_at":"2023-07-05T14:56:47.812Z","dependency_job_id":null,"html_url":"https://github.com/drudge/mongoose-findorcreate","commit_stats":{"total_commits":45,"total_committers":11,"mean_commits":4.090909090909091,"dds":0.6888888888888889,"last_synced_commit":"17d6cbdb105f4318c9c3f0ce2cb9dfa558473606"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-findorcreate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-findorcreate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-findorcreate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fmongoose-findorcreate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drudge","download_url":"https://codeload.github.com/drudge/mongoose-findorcreate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289428,"owners_count":20914464,"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":["mongoose","mongoose-plugin"],"created_at":"2024-09-24T13:52:21.347Z","updated_at":"2025-04-05T05:08:22.583Z","avatar_url":"https://github.com/drudge.png","language":"JavaScript","funding_links":[],"categories":["🛠 General Utilities"],"sub_categories":[],"readme":"Mongoose findOrCreate Plugin [![Build Status](https://secure.travis-ci.org/drudge/mongoose-findorcreate.png?branch=master)](https://travis-ci.org/drudge/mongoose-findorcreate)\n============================\n\nSimple plugin for [Mongoose](https://github.com/LearnBoost/mongoose) which adds\na findOrCreate method to models. This is useful for libraries like\n[Passport](http://passportjs.org) which require it.\n\n## Installation\n\n`npm install mongoose-findorcreate`\n\n## Usage\n\n```javascript\nvar findOrCreate = require('mongoose-findorcreate')\nvar ClickSchema = new Schema({ ... });\nClickSchema.plugin(findOrCreate);\nvar Click = mongoose.model('Click', ClickSchema);\n```\n\nThe Click model now has a findOrCreate static method\n\n```javascript\nClick.findOrCreate({ip: '127.0.0.1'}, function(err, click, created) {\n  // created will be true here\n  console.log('A new click from \"%s\" was inserted', click.ip);\n  Click.findOrCreate({}, function(err, click, created) {\n    // created will be false here\n    console.log('Did not create a new click for \"%s\"', click.ip);\n  })\n});\n```\n\nYou can also include properties that aren't used in the\nfind call, but will be added to the object if it is created.\n\n```javascript\nClick.create({ip: '127.0.0.1'}, {browser: 'Mozilla'}, function(err, val) {\n  Click.findOrCreate({ip: '127.0.0.1'}, {browser: 'Chrome'}, function(err, click) {\n    console.log('A click from \"%s\" using \"%s\" was found', click.ip, click.browser);\n    // prints A click from \"127.0.0.1\" using \"Mozilla\" was found\n  })\n});\n```\n\n### Promise Support\n\nChoose your Promise library by setting\n[`Mongoose.Promise`](http://mongoosejs.com/docs/promises.html).\n\nThe returned `Promise` shall resolve to an object with keys `doc` and\n`created` on success. It shall be rejected with `err` on failure.\n\n```javascript\n// Use environment-provided Promise (necessary to silence a Mongoose warning).\nmongoose.Promise = Promise;\n// To a findOrCreate().\nClick.findOrCreate({ip: '127.0.0.2'}).then(function (result) {\n  click = result.doc;\n  console.log('A click from', click.ip, ' using ', click.browser, ' was ', click.created ? 'created' : 'found');\n})\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2012-2017 Nicholas Penree \u0026lt;nick@penree.com\u0026gt;\n\nBased on [supergoose](https://github.com/jamplify/supergoose): Copyright (c) 2012 Jamplify\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrudge%2Fmongoose-findorcreate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrudge%2Fmongoose-findorcreate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrudge%2Fmongoose-findorcreate/lists"}